﻿using Glorysoft.Auto.Xfw;
using Glorysoft.Auto.Xfw.Component;
using Glorysoft.Auto.Xfw.Contract;
using Glorysoft.Auto.Xfw.Entities;
using Glorysoft.EAP.Core;
using Glorysoft.EAP.Core.Entities;
using Glorysoft.EAP.Core.Entities.DB;
using Glorysoft.EAP.Core.Entities.DB.Service;
using Glorysoft.EAP.Core.Enums;
using Glorysoft.EAP.RC.EAPClient;
using Glorysoft.EAP.RC.MES;
using Glorysoft.SECSwell;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Ocsp;
using Serilog;
using Serilog.Core;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using static Microsoft.Graph.GeneratedErrorConstants;

namespace Glorysoft.EAP.EC.SECS.OCR
{
    /// <summary>
    /// OCR联机
    /// </summary>
    public class OCRService : AbstractService
    {
        protected static Logger TrackoutLogger = XfwContext.LogManager.Create("TrackOutLogger");
        protected readonly XfwContext Context = XfwContext.Current;
        protected readonly Logger CimLogger;
        protected readonly string ServerName = "OCR";
        protected readonly string IsChangePPID = "ISCHANGEPPID";
        protected readonly string PPID = "PPID";
        protected readonly string LotID = "LOTID";
        protected readonly string PcID = "PCID";
        protected readonly string PCBID = "PCBID";
        protected readonly string IsCheckNeedleMark = "ISCHECKNEEDLEMARK";
        protected readonly string conn = "1";
        protected readonly string disConn = "-1";
        protected readonly string ProductID = "PRODUCTID";
        protected readonly string ProberCardID = "PROBERCARDID";
        protected readonly string OperatorID = "OPERATORID";
        protected readonly string IsTrace = "ISTRACE";
        protected readonly string LotLists = "LOTLISTS";
        protected readonly string LoadMode = "LOADMODE";
        protected readonly string ProberType = "PROBERTYPE";
        protected readonly string WaferName = "WAFERNAME";
        protected readonly string WaferIdCodeLists = "WAFERIDLISTS";
        protected readonly string SlotLists = "SLOTLISTS";
        protected readonly string RecommendOD = "RECOMMENDOD";
        protected readonly string RCFLAG = "RCFLAG";
        protected readonly string LotType = "LotType";

        EAPClientService ClientService = null;
        private DbService dbServer = null;

        ////定义一个委托
        //private delegate void actionByEvent(XfwArgs args, SECSMessage msg, string ocrName);
        ////定义一事件  Key，Value的键值对 
        //private static Dictionary<string, actionByEvent> EventDic = null;
        public OCRService()
        {
            try
            {
                CimLogger = XfwContext.LogManager.EapLogger;
                ClientService = new EAPClientService();
                //if (EventDic==null)
                //{
                //    EventDicAdd();
                //}
                dbServer = new DbService();
                //if (dbServer == null)
                //{
                //    dbServer = ReflectionHelper.Service<IDbService>();
                //}
            }
            catch (Exception ex)
            {
                CimLogger.Error(ex, $"{Name}.OCRService() Execute Error.");
            }
        }

        public virtual string Name => "OCRService";
        public string CurrentMethod => MethodBase.GetCurrentMethod().Name;


        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="args"></param>
        public void EQP_Initialize(XfwArgs args)
        {
            try
            {
                var eqpID = args.SECSData.Context.Name;
                args.Header[CItems.EqpID] = eqpID;
                args.Header[CItems.EqpStatus] = conn;
                Dict.Current.OCRName = eqpID;
                Console.WriteLine($"{eqpID}初始化");
                Dict.Current.OCRConnStatus = conn;
                var eqpType = args.SECSData.Context.Configuration.EqpType;
                if (eqpType == OCRType.TELOCR.ToString() || eqpType == OCRType.RaytrexOCR.ToString() ||
                    eqpType == OCRType.KeysightOCR.ToString() || eqpType == OCRType.DTS1000OCR.ToString() ||
                    eqpType == OCRType.ETS88OCR.ToString() || eqpType == OCRType.DOT800OCR.ToString() ||
                    eqpType == OCRType.Raytrex_E4980AOCR.ToString() || eqpType == OCRType.LianDongOCR.ToString() ||
                    eqpType == OCRType.SIDEA_LIANDONGOCR.ToString())
                {
                    Dict.Current.OCRTesterConnStatus = conn;//测试机通讯连接状态
                    Dict.Current.TesterType = eqpType;
                }

                if (!Dict.Current.OCRCurrentStatus.ContainsKey(eqpID))
                {
                    Dict.Current.OCRCurrentStatus.Add(eqpID, "");
                }

                CimLogger.Information($"{Name}.EQP_Initialize() Execute Success.");
                //dbServer.InsertMsgInfo("OCR连接成功", eqpID, Dict.Current.lotInfo.lotId);
                args.SetReturnCodeOK();
            }
            catch (Exception ex)
            {
                CimLogger.Error(ex, $"{Name}.EQP_Initialize() Execute Error.");
                args.SetReturnCodeNG($"EQP_Initialize:{ex.Message}");
            }
        }

        /// <summary>
        /// 断开连接
        /// </summary>
        /// <param name="args"></param>
        public void HsmsDisConnected(XfwArgs args)
        {
            try
            {
                var eqpID = args.SECSData.Context.Name;
                args.Header[CItems.EqpID] = eqpID;
                args.Header[CItems.EqpStatus] = disConn;
                Dict.Current.OCRConnStatus = disConn;
                Console.WriteLine($"{eqpID}已断开");
                if (Dict.Current.OCRCurrentStatus.ContainsKey(eqpID))
                {
                    Dict.Current.OCRCurrentStatus[eqpID] = "";
                }
                else
                {
                    Dict.Current.OCRCurrentStatus.Add(eqpID, "");
                }

                var eqpType = args.SECSData.Context.Configuration.EqpType;
                if (eqpType == OCRType.TELOCR.ToString() || eqpType == OCRType.RaytrexOCR.ToString() ||
                    eqpType == OCRType.KeysightOCR.ToString() || eqpType == OCRType.DTS1000OCR.ToString() ||
                    eqpType == OCRType.ETS88OCR.ToString() || eqpType == OCRType.DOT800OCR.ToString() ||
                    eqpType == OCRType.Raytrex_E4980AOCR.ToString() || eqpType == OCRType.LianDongOCR.ToString() ||
                    eqpType == OCRType.SIDEA_LIANDONGOCR.ToString())
                {
                    Dict.Current.OCRTesterConnStatus = disConn; //测试机通讯连接状态
                }

                CimLogger.Information($"{eqpID} HsmsDisConnected");
                //dbServer.InsertMsgInfo("OCR断开连接", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception e)
            {
                CimLogger.Error(e, $"{Name}.HsmsDisConnected() Execute Error.");
            }
        }


        #region 设备主动发送 Request

        /// <summary>
        /// 发送设备是否可以通讯
        /// </summary>
        /// <param name="args"></param>
        public void Send_S1F1_AreYouThere(XfwArgs args)
        {
            try
            {
                var eqpID = args.Header[CItems.EqpID].ToString();
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(1, 1);
                var requestMsg = trans.Primary;
                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S1F1, Timeout");
                    CimLogger.Warning($"{Name}.Send_S1F1_AreYouThere() Timeout");
                    return;
                }

                Dict.Current.OCRConnStatus = conn;
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S1F1_AreYouThere() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S1F1:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S1F1_AreYouThere() Execute Error.");
            }
        }


        public void Send_S1F3_SelectedRequest(XfwArgs args)
        {
            try
            {
                var eqpID = args.Header[CItems.EqpID].ToString();
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(eqpID, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG(
                        $"{Name}.Send_S1F3_SelectedRequest() The EAP has been switched Automatic Operation");
                    return;
                }

                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(1, 3);
                var requestMsg = trans.Primary;
                //var list = args.Header[CItems.List] as List<EqpParameters>;
                //var isFound = list.Any(o => o.IDType == "SVID");
                //if (!isFound) return;
                var list = new List<EqpParameters>();
                list.Add(new EqpParameters() { EdcID = "1", IDType = "SVID" });
                list.Add(new EqpParameters() { EdcID = "2", IDType = "SVID" });
                list.Add(new EqpParameters() { EdcID = "3", IDType = "SVID" });

                foreach (var item in list)
                {
                    if (item.IDType != "SVID") continue;
                    var secs = new SECSItem(eSECS_FORMAT.U2) { Value = item.EdcID };
                    requestMsg.Root.Add(secs);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S1F3, Timeout");
                    CimLogger.Information($"{Name}.Send_S1F3_SelectedRequest().Timeout");
                    return;
                }
                else
                {
                    for (int i = 1; i <= requestMsg.Root.ItemCount; i++)
                    {
                        var svid = requestMsg.Root.Item(i).Value.ToString();
                        var oFind = list.Find(o => o.EdcID == svid);
                        oFind.Value = DataUtils.convertToStr(replyMsg.Root.Item(i).Format, replyMsg.Root.Item(i).Value);
                    }
                }

                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S1F3_SelectedRequest() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S1F3:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S1F3_SelectedRequest() Execute Error.");
            }
        }

        /// <summary>
        /// 建立通讯
        /// </summary>
        /// <param name="args"></param>
        public void Send_S1F13_EstablishCommunicationsRequest(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName; // args.Header[CItems.EqpID]?.ToString();

                var context = XfwContext.GetSECSContext(eqpID);
                //var context = args.SECSData.Context;
                if (string.IsNullOrEmpty(eqpID))
                {
                    eqpID = args.SECSData.Context.Name;
                    context = XfwContext.GetSECSContext(eqpID);
                }

                var trans = context.GetTransaction(1, 13);
                var requestMsg = trans.Primary;
                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S1F13, Timeout");
                    CimLogger.Information($"{Name}.Send_S1F13_EstablishCommunicationsRequest(). Timeout");
                    //dbServer.InsertMsgInfo("发送S1F13启动OCR监控流程失败", eqpID, Dict.Current.lotInfo.lotId);
                    return;
                }

                Dict.Current.OCRConnStatus = conn;

                if (Dict.Current.TesterType == OCRType.TELOCR.ToString() ||
                    Dict.Current.TesterType == OCRType.RaytrexOCR.ToString() ||
                    Dict.Current.TesterType == OCRType.KeysightOCR.ToString() ||
                    Dict.Current.TesterType == OCRType.DTS1000OCR.ToString() ||
                    Dict.Current.TesterType == OCRType.ETS88OCR.ToString() ||
                    Dict.Current.TesterType == OCRType.DOT800OCR.ToString() ||
                    Dict.Current.TesterType == OCRType.Raytrex_E4980AOCR.ToString() ||
                    Dict.Current.TesterType == OCRType.LianDongOCR.ToString() ||
                    Dict.Current.TesterType == OCRType.SIDEA_LIANDONGOCR.ToString())
                {
                    Dict.Current.OCRTesterConnStatus = conn;
                }

                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S1F13_EstablishCommunicationsRequest() Execute Success.");
                //dbServer.InsertMsgInfo("发送S1F13启动OCR监控流程成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S1F13:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S1F13_EstablishCommunicationsRequest() Execute Error.");
            }
        }

        #endregion

        /// <summary>
        /// 请求offline
        /// </summary>
        /// <param name="args"></param>
        public void Send_S1F15_OfflineRequest(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(1, 15);
                var requestMsg = trans.Primary;
                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S1F15, Timeout");
                    CimLogger.Warning($"{Name}.Send_S1F15_OfflineRequest() Timeout.");
                    //dbServer.InsertMsgInfo("发送S1F15 OCR Offline 停止流程失败", eqpID, Dict.Current.lotInfo.lotId);
                    return;
                }

                //var eqpID = args.SECSData.Context.Name;
                args.Header[CItems.EqpID] = eqpID;
                args.Header[CItems.ReturnCode] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S1F15_OfflineRequest() Execute Success.");
                //dbServer.InsertMsgInfo("发送S1F15 OCR Offline 停止流程成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.Header[CItems.ReturnCode] = "-1";
                args.SetReturnCodeNG("S1F15:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S1F15_OfflineRequest() Execute Error.");
            }
        }

        /// <summary>
        /// 请求online
        /// </summary>
        /// <param name="args"></param>
        public void Send_S1F17_OnlineRequest(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName; //args.SECSData.Context.Name;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(1, 17);
                var requestMsg = trans.Primary;
                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S1F17, Timeout");
                    CimLogger.Information($"{Name}.Send_S1F17_OnlineRequest() Timeout.");
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Value;
                if (retCode[0] != 0 && retCode[0] != 2)
                {
                    args.SetReturnCodeNG("Send S1F17, Equipment Reject.");
                    //dbServer.InsertMsgInfo("发送S1F17 OCR Online失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.EqpID] = eqpID;
                args.Header[CItems.ReturnCode] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S1F17_OnlineRequest() Execute Success.");
                //dbServer.InsertMsgInfo("发送S1F17 OCR Online 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.Header[CItems.ReturnCode] = "-1";
                args.SetReturnCodeNG("S1F17:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S1F17_OnlineRequest() Execute Error.");
            }
        }


        /// <summary>
        /// 查询设备的ECID
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F13_EqConstantRequest(XfwArgs args)
        {
            try
            {
                var eqpID = args.Header[CItems.EqpID].ToString();
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(eqpID, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F13_EqConstantRequest() The EAP has been switched Automatic Operation");
                    return;
                }

                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 13);
                var requestMsg = trans.Primary;
                //  var list = args.Header[CItems.List] as List<EqpParameters>;
                var list = new List<EqpParameters>();
                list.Add(new EqpParameters() { EdcID = "10", IDType = "ECID" });
                list.Add(new EqpParameters() { EdcID = "20", IDType = "ECID" });
                list.Add(new EqpParameters() { EdcID = "33", IDType = "ECID" });
                var isFound = list.Any(o => o.IDType == "ECID");
                if (!isFound) return;
                foreach (var item in list)
                {
                    if (item.IDType != "ECID") continue;
                    var secs = new SECSItem(eSECS_FORMAT.U2) { Value = item.EdcID };
                    requestMsg.Root.Add(secs);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F13, Timeout");
                    return;
                }
                else
                {
                    for (int i = 1; i <= requestMsg.Root.ItemCount; i++)
                    {
                        var ecid = requestMsg.Root.Item(i).Value.ToString();
                        var oFind = list.Find(o => o.EdcID == ecid);
                        oFind.Value = DataUtils.convertToStr(replyMsg.Root.Item(i).Format, replyMsg.Root.Item(i).Value);
                    }
                }

                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F13_EqConstantRequest() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F13:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F13_EqConstantRequest() Execute Error.");
            }
        }

        #region FP3000-FLEX命令

        /// <summary>
        /// 发送给P命令：TrackIn
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_TrackIn(XfwArgs args)
        {
            try
            {
                var ocrName = Dict.Current.OCRName;
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(ocrName, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG($"{Name}.Send_S2F41_TrackIn() The EAP has been switched Automatic Operation");
                    return;
                }

                var testModel = Dict.Current.lotInfo.TestMode;

                var customerLotId = Dict.Current.lotInfo.customerLotId; //args.Header[CItems.CustomerLotId]?.ToString();
                var eqpID = Dict.Current.lotInfo.eqptID; //args.Header[CItems.EqpID].ToString();
                var recipeName = Dict.Current.lotInfo.proberRecipe;
                var lotID = Dict.Current.lotInfo.lotId;
                var lotLists = Dict.Current.lotInfo.LotLists; //选片

                var mesLists = Dict.Current.lotInfo.MesWaferList; //mes里的片集合
                var LoadModeValue = "";
                if (!string.IsNullOrEmpty(lotLists))
                {
                    if (Dict.Current.lotInfo.IsFullmeasurement == "true")
                    {
                        if (testModel == "Sample")
                        {
                            //选择的全测  实际上所有Wafer信息与MES需要测试的Wafer信息不同
                            LoadModeValue = "SAMPLE";
                            Dict.Current.lotInfo.LotLists = lotLists + "-" + "SAMPLE";
                        }
                        else
                        {
                            //全测 testModel=Sequential
                            Dict.Current.lotInfo.LotLists = lotLists + "-" + "SEQUENTIAL";
                            lotLists = "";
                            LoadModeValue = "SEQUENTIAL"; //SEQUENTIAL
                        }

                    }
                    else
                    {
                        if (testModel == "Assign") //选择的信息匹配
                        {
                            //指定测试 Assign
                            LoadModeValue = "ASSIGN";
                            lotLists = lotLists.Split(';')[0];
                            Dict.Current.lotInfo.LotLists = lotLists + "-" + "ASSIGN";
                        }
                        else
                        {
                            //抽测 Sample
                            LoadModeValue = "SAMPLE";
                            Dict.Current.lotInfo.LotLists = lotLists + "-" + "SAMPLE";
                        }
                    }
                }

                if (!string.IsNullOrEmpty(customerLotId)) //如果这个值不为空，则Prober识别该值
                {
                    lotID = customerLotId;
                }
                else
                {
                    if (!string.IsNullOrEmpty(lotID))
                    {
                        var index = lotID.IndexOf('.');
                        if (index > 0)
                        {
                            lotID = lotID.Substring(0, index); //比如AA9370.01   Prober只识别AA9370，去除小数点后的值
                        }
                    }
                }

                if (Dict.Current.IsEngineeringMode == "Y") //如果是工程片测试，则使用配置的Recipe和LotID
                {
                    lotID = Dict.Current.ProberLotID;
                    recipeName = Dict.Current.ProberRecipe;
                }

                if (string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning($"{Name}.Send_S2F41_TrackIn() 发送给OCR的数据异常.lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_TrackIn(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var isCheckNeedleMark = "Y";
                var context = XfwContext.GetSECSContext(ocrName);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "TrackIn";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                var IsChangePPIDList = new SECSItem(eSECS_FORMAT.LIST);
                IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsChangePPID });
                IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "Y" }); //Y ：更换  N：不更换//rpa 识别
                secondlist.Add(IsChangePPIDList);

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //Recipe名称
                secondlist.Add(RecipeNameList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);

                var IsCheckNeedleMarkList = new SECSItem(eSECS_FORMAT.LIST);
                IsCheckNeedleMarkList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsCheckNeedleMark });
                IsCheckNeedleMarkList.Add(new SECSItem(eSECS_FORMAT.ASCII)
                { Value = isCheckNeedleMark }); //Y ：检查  N：不检查
                secondlist.Add(IsCheckNeedleMarkList);

                var LoadModes = new SECSItem(eSECS_FORMAT.LIST);
                LoadModes.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LoadMode });
                LoadModes.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LoadModeValue }); //选片的模式
                secondlist.Add(LoadModes);

                var LotListsList = new SECSItem(eSECS_FORMAT.LIST);
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "SLOTLISTS" });
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotLists }); //  选片集合
                secondlist.Add(LotListsList);


                requestMsg.Root.Add(secondlist);

                var messagess = TranslateMsg.GetTranslation("SendS2F41TrackIn");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.Header[CItems.S2F41Ack] = "2";
                    args.SetReturnCodeNG("Send S2F41:TrackIn, Timeout");
                    CimLogger.Information($"{Name}.Send_S2F41_TrackIn() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41-TrackIn 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.Header[CItems.recipeAck] = (byte[])replyMsg.Root.Item(2).Item(2).Item(2).Value;
                    args.Header[CItems.lotIDAck] = (byte[])replyMsg.Root.Item(2).Item(3).Item(2).Value;
                    args.Header[CItems.S2F41Ack] = "1";
                    args.SetReturnCodeNG("Send S2F41:TrackIn, Equipment Reject.");
                    CimLogger.Information($"{Name}.Send_S2F41_TrackIn() Equipment Reject.");
                    //dbServer.InsertMsgInfo("发送S2F41-TrackIn 失败，OCR回复执行失败", eqpID, Dict.Current.lotInfo.lotId);
                    return;
                }

                args.Header[CItems.S2F41Ack] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_TrackIn() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-TrackIn 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_TrackIn:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_TrackIn() Execute Error.");
            }
        }
        /// <summary>
        /// 发送给P进片命令：StartTest
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_StartTest(XfwArgs args)
        {
            try
            {
                var ocrName = Dict.Current.OCRName;
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(ocrName, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_StartTest() The EAP has been switched Automatic Operation");
                    return;
                }

                //if (Dict.Current.NeedleResult.ContainsKey(CItems.CheckNeedlePitch))
                //{
                //    if (Dict.Current.NeedleResult[CItems.CheckNeedlePitch] == false)
                //    {
                //        args.SetReturnCodeNG($"Send S2F41:CheckNeedlePitch:{Dict.Current.NeedleResult[CItems.CheckNeedlePitch]}.");
                //        return;
                //    }
                //}
                //if (Dict.Current.NeedleResult.ContainsKey(CItems.CheckNeedleMark))
                //{
                //    if (Dict.Current.NeedleResult[CItems.CheckNeedleMark] == false)
                //    {
                //        args.SetReturnCodeNG($"Send S2F41:CheckNeedlePitch:{Dict.Current.NeedleResult[CItems.CheckNeedleMark]}.");
                //        return;
                //    }
                //}
                //dbServer.InsertMsgInfo("OCR点击StartTest前 二次比对Recipe成功 ", ocrName, Dict.Current.lotInfo.lotId);

                var recipeName = Dict.Current.lotInfo.proberRecipe;
                if (string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning($"{Name}.Send_S2F41_StartTest()发送给OCR的数据异常. ，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(ocrName, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_StartTest(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                //var ocrName = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = ocrName;
                var IsAlignment = Dict.Current.lotInfo.Alignment; // "N"
                var context = XfwContext.GetSECSContext(ocrName);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "StartTest";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                var IsChangePPIDList = new SECSItem(eSECS_FORMAT.LIST);
                IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsCheckNeedleMark }); //是否对针标志
                IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsAlignment }); //Y ：对针  N：不对针
                secondlist.Add(IsChangePPIDList);

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //Recipe名称
                secondlist.Add(RecipeNameList);

                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41StartTest");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(ocrName, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;

                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTest, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_StartTest() Timeout.");
                    args.Header[CItems.S2F41Ack] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-StartTest 失败，接口超时", ocrName, Dict.Current.lotInfo.lotId);
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTest, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_StartTest() Equipment Reject.");
                    args.Header[CItems.S2F41Ack] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-StartTest 失败，OCR执行失败", ocrName, Dict.Current.lotInfo.lotId);
                    return;
                }

                if (Dict.Current.ProberRunStatus == "0")
                {
                    Dict.Current.ProberRunStatus = "1";
                }

                args.Header[CItems.S2F41Ack] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information(
                    $"{Name}.Send_S2F41_StartTest() Execute Success.recipeName：{recipeName}，IsAlignment：{IsAlignment}");
                //dbServer.InsertMsgInfo("发送S2F41-StartTest 成功", ocrName, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_StartTest:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_StartTest() Execute Error.");
            }
        }

        #endregion

        #region TEL-Keysight 命令

        /// <summary>
        /// 发送LotID、Recipe等给Tester
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_DownLoadRecipe(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "DownLoadRecipe";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                // var customerLotId = Dict.Current.lotInfo.customerLotId; // args.Header[CItems.CustomerLotId]?.ToString();
                var productId = Dict.Current.lotInfo.testerProgram; //Dict.Current.lotInfo.productId; //"productId001"; 
                var userName = Dict.Current.lotInfo.userName; // "ME0001"; 
                var recipeName = Dict.Current.lotInfo.proberRecipe; // "rcpName001";
                var isTrace = "0"; // Dict.Current.lotInfo.Alignment;  //"0";
                var lotID = Dict.Current.lotInfo.lotId; //args.Header[CItems.LotID]?.ToString();  "AA0001"; 
                var lotLists = Dict.Current.lotInfo.LotLists; //如果测25片则 不选片 此值传""

                if (!string.IsNullOrEmpty(lotLists))
                {
                    //优化全测，取mes 的值做对比
                    if (Dict.Current.lotInfo.IsFullmeasurement == "true")
                    {
                        Dict.Current.lotInfo.LotLists = lotLists + "-" + "SEQUENTIAL";
                        lotLists = "";
                        // LoadModeValue = "SEQUENTIAL";//SEQUENTIAL
                    }
                }

                // var lotLists = Dict.Current.lotInfo.LotLists.Length > 48 ? "" : Dict.Current.lotInfo.LotLists; //如果测25片则 不选片 此值传""
                var proberType = Dict.Current.EAPName == "EAPTelKeysight" ? "TEL_Keysight" : "TEL_Raytrex";

                if (string.IsNullOrEmpty(productId) || string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning(
                        $"{Name}.Send_S2F41_DownLoadRecipe() 发送给OCR的数据异常.productId：{productId}，lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_DownLoadRecipe(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //RecipeName
                secondlist.Add(RecipeNameList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);


                var OperatorIDList = new SECSItem(eSECS_FORMAT.LIST);
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = OperatorID });
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = userName }); //用户名ID 
                secondlist.Add(OperatorIDList);

                var ProductIDList = new SECSItem(eSECS_FORMAT.LIST);
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProductID });
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = productId }); //产品ID 
                secondlist.Add(ProductIDList);

                var IsTraceList = new SECSItem(eSECS_FORMAT.LIST);
                IsTraceList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsTrace });
                IsTraceList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = isTrace }); //是否需要针痕检测
                secondlist.Add(IsTraceList);

                var LotListsList = new SECSItem(eSECS_FORMAT.LIST);
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotLists });
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotLists }); //  选片集合
                secondlist.Add(LotListsList);

                var ProberTypeList = new SECSItem(eSECS_FORMAT.LIST);
                ProberTypeList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProberType });
                ProberTypeList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = proberType }); //  ProberType区分
                secondlist.Add(ProberTypeList);

                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41DownLoadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:DownLoadRecipe, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_DownLoadRecipe() Timeout.");

                    args.Header[CItems.S2F41AckToTester] = "2";
                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_DownLoadRecipe() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_DownLoadRecipe:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_DownLoadRecipe() Execute Error.");
            }
        }

        /// <summary>
        /// 设置测试机LotID、Recipe、OperatorID  
        /// </summary>
        public void Send_S2F41_SetRecipe(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "SetRecipe";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                var productId = Dict.Current.lotInfo.testerProgram;
                var userName = Dict.Current.lotInfo.userName;
                var lotID = Dict.Current.lotInfo.lotId;

                if (string.IsNullOrEmpty(productId) || string.IsNullOrEmpty(lotID))
                {
                    CimLogger.Warning($"{Name}.Send_S2F41_SetRecipe() 发送给OCR的数据异常.productId：{productId}，lotID{lotID}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_SetRecipe(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var recipeName = Dict.Current.lotInfo.proberRecipe;
                if (string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning($"{Name}.Send_S2F41_StartTest()发送给OCR的数据异常. ，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_StartTest(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);

                var ProductIDList = new SECSItem(eSECS_FORMAT.LIST);
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProductID });
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = productId }); //产品ID 
                secondlist.Add(ProductIDList);

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //Recipe名称
                secondlist.Add(RecipeNameList);

                var OperatorIDList = new SECSItem(eSECS_FORMAT.LIST);
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = OperatorID });
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = userName }); //用户名ID 
                secondlist.Add(OperatorIDList);

                var lotLists = Dict.Current.lotInfo.LotLists;  //如果测25片则 不选片 此值传""
                var LotListsList = new SECSItem(eSECS_FORMAT.LIST);
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotLists });
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotLists });  //  选片集合
                secondlist.Add(LotListsList);

                requestMsg.Root.Add(secondlist);

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:SetRecipe, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_SetRecipe() Timeout.");

                    args.Header[CItems.S2F41AckToTester] = "2";
                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_SetRecipe() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("Send_S2F41_SetRecipe:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_SetRecipe() Execute Error.");
            }
        }

        #endregion

        #region TEL-Raytrex 命令

        /// <summary>
        /// 发送LotID、Recipe等给Tester
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_DownLoadRecipeToTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "DownLoadRecipeToTester"; //
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);


                var userName = Dict.Current.lotInfo.userName;
                var recipeName = Dict.Current.lotInfo.testerProgram;
                var lotID = Dict.Current.lotInfo.lotId;
                if (string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning(
                        $"{Name}.Send_S2F41_DownLoadRecipeToTester() 发送给OCR的数据异常，lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_DownLoadRecipeToTester(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //RecipeName
                secondlist.Add(RecipeNameList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);


                var OperatorIDList = new SECSItem(eSECS_FORMAT.LIST);
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = OperatorID });
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = userName }); //用户名ID 
                secondlist.Add(OperatorIDList);


                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41DownLoadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:DownLoadRecipeToTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_DownLoadRecipeToTester() Timeout.");

                    args.Header[CItems.S2F41AckToTester] = "2";
                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_DownLoadRecipeToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Error.");
            }
        }

        /// <summary>
        /// 发送开始测试给Prober
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_StartTestToProber(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var recipeName = Dict.Current.lotInfo.testerProgram;
                // var lotLists = Dict.Current.lotInfo.LotLists;
                var lotLists =
                    Dict.Current.lotInfo.LotLists; //> 48 ? "" : Dict.Current.lotInfo.LotLists; //如果测25片则 不选片 此值传""

                if (!string.IsNullOrEmpty(lotLists))
                {
                    //优化全测，取mes 的值做对比
                    if (lotLists.Split(';').Count() == Dict.Current.Qty)
                    {
                        lotLists = "";
                        CimLogger.Information("Execute Success.全测，发送空值");
                    }
                }

                //if (!string.IsNullOrEmpty(lotLists))
                //{
                //    if (lotLists.Split(';').Count() >= 25)
                //    {
                //        lotLists = "";
                //    }
                //}
                //定义waferName，MES传值带_与机台只有-，程序预处理
                //var waferName = Dict.Current.lotInfo.proberRecipe;
                string waferName = Dict.Current.lotInfo.proberRecipe;
                if (Dict.Current.lotInfo.proberRecipe.Contains("_"))
                {
                    waferName = Dict.Current.lotInfo.proberRecipe.Replace("_", "-");
                }

                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "StartTestToProber";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41StartTestToProber");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var WaferNameList = new SECSItem(eSECS_FORMAT.LIST);
                WaferNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = WaferName });
                WaferNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = waferName }); //Prober RecipeName
                secondlist.Add(WaferNameList);

                var LotListsList = new SECSItem(eSECS_FORMAT.LIST);
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotLists });
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotLists }); //选片集合
                secondlist.Add(LotListsList);

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //RecipeName
                secondlist.Add(RecipeNameList);

                requestMsg.Root.Add(secondlist);

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTestToProber, Timeout");
                    CimLogger.Information($"{Name}.Send_S2F41_StartTestToProber() Timeout.");

                    args.Header[CItems.S2F41AckToTester] = "2";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTestToProber, Equipment Reject.");
                    CimLogger.Information($"{Name}.Send_S2F41_StartTestToProber() Equipment Reject.");

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_StartTestToProber() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_StartTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_StartTestToProber() Execute Error.");
            }
        }

        /// <summary>
        /// 发送开始测试给Tester
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_StartTestToTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "StartTestToTester";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41StartTestToTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTestToTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_StartTestToTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41-StartTestToTester 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTestToTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_StartTestToTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-StartTestToTester 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_EndTestToTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-StartTestToTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }

        #endregion

        #region 设备上报waferEnd

        public void WaferEndReport(XfwArgs args)
        {
            try
            {
                STDF stdf = (STDF)args.Header[CItems.STDF];
                var waferId = stdf.waferId;
                var passNo = stdf.passNo;
              //  var startTime = Convert.ToDateTime(stdf.startTime);
              //  var finishTime = Convert.ToDateTime(stdf.finishTime);
                //STEP 1 ===>>判断这次STDF上报是否应该被处理
                //1、更新程序导致没有进站缓存跳过处理。
                //2、waferId不在历史作业批次内跳过处理
                //3、waferId对应测试开始时间小于缓存

                if ((string.IsNullOrEmpty(waferId) || string.IsNullOrEmpty(passNo)) || Dict.Current.TrackOutLotQueue.Count == 0)
                {
                    TrackoutLogger.Information($"参数为空或更新程序跳过处理{waferId}{passNo}");
              //      ClientService.ShowMessage("更新程序导致缓存没有批次信息时跳过处理", waferId, passNo);
                    return;
                }
                string lotId = "";
                Wafer wafer1 = null; ;
                foreach (var item in Dict.Current.TrackOutLotQueue)
                {
                    var lotInfo1 = item.Value;
                    wafer1 = new Wafer();
                    wafer1 = lotInfo1.waferList.FirstOrDefault(o => o.waferId == waferId || o.waferId.Substring(0, o.waferId.Length - 3) == waferId);
                    if (wafer1 == null)
                    {
                        continue;
                    }
                    else {
                        lotId = item.Key;
                        break;
                    }

                }

                if (wafer1 == null )
                {
                    TrackoutLogger.Information(string.Format("该wafer对应Lot 未使用EAP进站", wafer1));
                    ClientService.ShowMessage("该wafer 未使用EAP进站", wafer1);
                    return;
                }
                if (string.IsNullOrEmpty(lotId)) {
                    TrackoutLogger.Information(string.Format("缓存中没有找到批次号"+ wafer1));
                }
                var lotInfo = Dict.Current.TrackOutLotQueue[lotId];

                if (wafer1.processFlag == "Y" && !lotInfo.retestFlag)
                {
                    if (wafer1.passNo == passNo)
                    {
                        TrackoutLogger.Information(string.Format("相同事件上报，忽略处理"));
                        return;
                    }
                    else
                    {
                            TrackoutLogger.Information(string.Format("当前批次作业中上报重复waferID,此批次将被hold。WaferID:{0},lotId:{1}", waferId, lotId));
                            MESService mesService = new MESService();
                            mesService.HoldLotByLotInfo(lotInfo, $"批次:{lotId}在未作业结束前上报两次相同waferID的测试数据。请确认是否出现测试数据覆盖问题" +
                            $"waferID:{wafer1.waferId}");
                            ClientService.ShowMessage("当前批次作业中上报重复waferID,此批次将被hold。WaferID:{0},lotId:{1}", waferId, lotId);
                    }
                }
                ClientService.ShowMessage("EAP>设备上报WaferId：{0} 测试结束,PassDie数量：{1}", waferId, passNo);
                wafer1.processFlag = "Y";
                wafer1.passNo = passNo;
                wafer1.processState = ProcessState.ProcessEnd.ToString();
                //wafer1.startTime = startTime;
                //wafer1.finishTime = finishTime;
                if (! string.IsNullOrEmpty(stdf.p50Median))
                {
                    wafer1.p50Median = stdf.p50Median;
                }
              //  TrackoutLogger.Information(string.Format("更新Wafer状态"+JsonUtils.Serialization(wafer1)));


            }
            catch (Exception e)
            {
                TrackoutLogger.Information("WaferEnd异常："+e.StackTrace);
            }
        }

        #endregion

        /// <summary>
        /// UF2000 流程 ，可公用，UF2000 可搭配DTS1000/ETS800/DOT800
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_UF2000_ProberDownloadRecipe(XfwArgs args)
        {
            try
            {
                var ocrName = Dict.Current.OCRName;
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(ocrName, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_UF2000ProberDownloadRecipe() The EAP has been switched Automatic Operation");
                    return;
                }

                var customerLotId = Dict.Current.lotInfo.customerLotId; //args.Header[CItems.CustomerLotId]?.ToString();
                var eqpID = Dict.Current.lotInfo.eqptID; //args.Header[CItems.EqpID].ToString();
                var productid = Dict.Current.lotInfo.productId;
                var recipeName = Dict.Current.lotInfo.proberRecipe;
                ; //args.Header[CItems.ProberRecipe]?.ToString();
                var lotID = Dict.Current.lotInfo.lotId; //args.Header[CItems.LotID]?.ToString();
                var lotLists = Dict.Current.lotInfo.LotLists; //选片
                var IsAlignment = Dict.Current.lotInfo.Alignment; // "N";
                var IsChangeRecipeValue = Dict.Current.lotInfo.TestSiteMode; // "none/1/8";  site单/多
                var TestMode = Dict.Current.lotInfo.TestMode.Split("-")[0];
                var RecommendODValue = Dict.Current.RecommendOD;
                var rcflag = Dict.Current.lotInfo.rcflag; //runcard 标记：N/Y
                var probercard = Dict.Current.lotInfo.ProberCardId;
                var mesLists = Dict.Current.lotInfo.MesWaferList;
                var lotType = Dict.Current.lotInfo.lotType;
                var unitidLists = Dict.Current.lotInfo.UnitidLists;
                CimLogger.Information("lotType:" + lotType);
                CimLogger.Information("原始lotLists:" + lotLists);
                CimLogger.Information("MESmesLists:" + mesLists);
                CimLogger.Information("UnitidLists:" + unitidLists);
                var LoadModeValue = "";
                if (!string.IsNullOrEmpty(lotLists))
                {
                    //Sequential;Sample;Assign
                    if (TestMode == WaferTestModeType.Sequential.ToString())
                    {
                        Dict.Current.lotInfo.LotLists = lotLists + "-" + "SEQUENTIAL";
                        lotLists = "";
                        LoadModeValue = "SEQUENTIAL"; //SEQUENTIAL
                    }
                    else if (TestMode == WaferTestModeType.Sample.ToString())
                    {
                        //抽测 sampleID
                        LoadModeValue = "SAMPLE";
                        Dict.Current.lotInfo.LotLists = lotLists + "-" + "SAMPLE";
                    }
                    else if (TestMode == WaferTestModeType.Assign.ToString())
                    {
                        //走第三个按钮ASSIGN
                        LoadModeValue = "ASSIGN";
                        lotLists = lotLists.Split(';')[0];
                        Dict.Current.lotInfo.LotLists = lotLists + "-" + "ASSIGN";
                    }
                }

                //if (!string.IsNullOrEmpty(customerLotId)) //如果这个值不为空，则Prober识别该值
                //{
                //    lotID = customerLotId;
                //}
                //else
                //{
                //    if (!string.IsNullOrEmpty(lotID))
                //    {
                //        var index = lotID.IndexOf('.');
                //        if (index > 0)
                //        {
                //            lotID = lotID.Substring(0, index);//比如AA9370.01   Prober只识别AA9370
                //        }
                //    }
                //}             
                if (Dict.Current.IsEngineeringMode == "Y") //如果时工程片测试，则使用配置的Recipe和LotID
                {
                    lotID = Dict.Current.ProberLotID;
                    recipeName = Dict.Current.ProberRecipe;
                }

                if (string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning(
                        $"{Name}.Send_S2F41_UF2000ProberDownloadRecipe() 发送给OCR的数据异常.lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.S2F41_UF2000ProberDownloadRecipe(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                if (IsChangeRecipeValue == "8")
                {
                    if (recipeName.Contains("01S"))
                    {
                        //将含01S替换为08S                                        
                        recipeName = Regex.Replace(recipeName, @"01S", "08S");
                    }
                }

                if (IsChangeRecipeValue == "4")
                {
                    if (recipeName.Contains("01S"))
                    {
                        //将含01S替换为08S                                        
                        recipeName = Regex.Replace(recipeName, @"01S", "04S");
                    }
                }

                var isCheckNeedleMark = "Y";
                var context = XfwContext.GetSECSContext(ocrName);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "UF2000_PROBERDOWNLOADRECIPE";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                //var IsChangePPIDList = new SECSItem(eSECS_FORMAT.LIST);
                //IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsChangePPID });
                //IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "Y" }); //Y ：更换  N：不更换//rpa 识别
                //secondlist.Add(IsChangePPIDList);

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //Recipe名称
                secondlist.Add(RecipeNameList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);

                var ProductIDList = new SECSItem(eSECS_FORMAT.LIST);
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProductID });
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = productid }); //产品ID 
                secondlist.Add(ProductIDList);

                var LoadModes = new SECSItem(eSECS_FORMAT.LIST);
                LoadModes.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LoadMode });
                LoadModes.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LoadModeValue }); //选片的模式
                secondlist.Add(LoadModes);

                var LotListsList = new SECSItem(eSECS_FORMAT.LIST);
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = SlotLists });
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotLists }); //  选片集合
                secondlist.Add(LotListsList);

                var WaferIdList = new SECSItem(eSECS_FORMAT.LIST);
                WaferIdList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = WaferIdCodeLists });
                WaferIdList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = unitidLists }); //  MES wafercode 集合
                secondlist.Add(WaferIdList);

                var IsCheckNeedleMarkList = new SECSItem(eSECS_FORMAT.LIST);
                IsCheckNeedleMarkList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsCheckNeedleMark });
                IsCheckNeedleMarkList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsAlignment }); //Y ：对针  N：不对针
                secondlist.Add(IsCheckNeedleMarkList);

                var RecommendODList = new SECSItem(eSECS_FORMAT.LIST);
                RecommendODList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = RecommendOD });
                RecommendODList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = RecommendODValue }); //OD推荐值
                secondlist.Add(RecommendODList);

                var ProberCardList = new SECSItem(eSECS_FORMAT.LIST);
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProberCardID });
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = probercard }); //针卡ID 
                secondlist.Add(ProberCardList);

                var Rcflagist = new SECSItem(eSECS_FORMAT.LIST);
                Rcflagist.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = RCFLAG });
                Rcflagist.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = rcflag }); //runcard 标记
                secondlist.Add(Rcflagist);

                var lotTypeList = new SECSItem(eSECS_FORMAT.LIST);
                lotTypeList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotType });
                lotTypeList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotType }); //lotType
                secondlist.Add(lotTypeList);

                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41_UF2000_ProberDownloadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.Header[CItems.S2F41Ack] = "2";
                    args.SetReturnCodeNG("Send_S2F41:UF2000ProberDownloadRecipe, Timeout");
                    CimLogger.Information($"{Name}.Send_S2F41_UF2000ProberDownloadRecipe() Timeout.");
                   
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.Header[CItems.recipeAck] = (byte[])replyMsg.Root.Item(2).Item(2).Item(2).Value;
                    args.Header[CItems.lotIDAck] = (byte[])replyMsg.Root.Item(2).Item(3).Item(2).Value;
                    args.Header[CItems.S2F41Ack] = "1";
                    args.SetReturnCodeNG("Send_S2F41:UF2000ProberDownloadRecipe, Equipment Reject.");
                    CimLogger.Information($"{Name}.Send_S2F41:UF2000ProberDownloadRecipe() Equipment Reject.");
                   
                    return;
                }

                args.Header[CItems.S2F41Ack] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41:UF2000ProberDownloadRecipe() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-UF2000ProberDownloadRecipe 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_UF2000ProberDownloadRecipe:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41:UF2000ProberDownloadRecipe() Execute Error.");
            }
        }


        /// <summary>
        /// AMIDA 流程 ，可公用，AMIDA 可搭配UF2000
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_Amida_TesterDownloadRecipe(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.TesterID;
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(eqpID, MessageType.Info, messages, MessageOrigin.Daemon);
                    args.SetReturnCodeNG($"{Name}.Send_DownLoadTestProgram() The EAP has been switched Automatic Operation");
                    return;
                }
                var recipeName = Dict.Current.lotInfo.testerProgram;
                var lotid = args.Header[CItems.LotID]?.ToString();
                var operatorid = args.Header[CItems.UserName]?.ToString();
                var IsChangeRecipeValue = Dict.Current.lotInfo.TestSiteMode;// "None/1/8";  site单/多
                if (IsChangeRecipeValue == "8")
                {
                    if (recipeName.Contains("01S"))
                    {
                        //将含01S替换为08S                                        
                        recipeName = Regex.Replace(recipeName, @"01S", "08S");
                    }
                }
                if (IsChangeRecipeValue == "4")
                {
                    if (recipeName.Contains("01S"))
                    {
                        //将含01S替换为04S                                        
                        recipeName = Regex.Replace(recipeName, @"01S", "04S");
                    }
                }
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "AMIDA_TESTERDOWNLOADRECIPE";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);


                var eqpIdList = new SECSItem(eSECS_FORMAT.LIST);
                eqpIdList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = CItems.TesterEqpID });
                eqpIdList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = eqpID }); //设备名称
                secondlist.Add(eqpIdList);

                var lotId = new SECSItem(eSECS_FORMAT.LIST);
                lotId.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = CItems.LotID });
                lotId.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = Dict.Current.lotInfo.lotId }); //LotID
                secondlist.Add(lotId);

                var ProductIDList = new SECSItem(eSECS_FORMAT.LIST);
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = CItems.ProductID });
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = Dict.Current.lotInfo.testerProgram }); //产品ID 
                secondlist.Add(ProductIDList);

                var SortID = new SECSItem(eSECS_FORMAT.LIST);
                SortID.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = CItems.SortID });
                SortID.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "CP1" });
                secondlist.Add(SortID);

                var TestProgram = new SECSItem(eSECS_FORMAT.LIST);
                TestProgram.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = CItems.TestProgram });
                TestProgram.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName });
                secondlist.Add(TestProgram);

                var PIBID = new SECSItem(eSECS_FORMAT.LIST);
                PIBID.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = CItems.PIBID });
                PIBID.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = CItems.PIBIDValue }); //  MES wafercode 集合
                secondlist.Add(PIBID);

                var ProbecardIDLeft = new SECSItem(eSECS_FORMAT.LIST);
                ProbecardIDLeft.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = CItems.ProberCardIDLeft });
                ProbecardIDLeft.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = Dict.Current.lotInfo.ProberCardId }); //Y ：对针  N：不对针
                secondlist.Add(ProbecardIDLeft);

                var ProbeCardIDRignt = new SECSItem(eSECS_FORMAT.LIST);
                ProbeCardIDRignt.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = CItems.ProberCardIDRight });
                ProbeCardIDRignt.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "0000" });
                secondlist.Add(ProbeCardIDRignt);

                var OPID = new SECSItem(eSECS_FORMAT.LIST);
                OPID.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = CItems.operationId });
                OPID.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = Dict.Current.lotInfo.userName });
                secondlist.Add(OPID);

                var runMode = new SECSItem(eSECS_FORMAT.LIST);
                runMode.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = CItems.RunModeSelected });
                runMode.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "Normal Test" });
                secondlist.Add(runMode);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41_AMIDA_TesterDownloadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.Header[CItems.S2F41Ack] = "2";
                    args.SetReturnCodeNG("Send_S2F41:SendS2F41_AMIDA_TesterDownloadRecipe, Timeout");
                    CimLogger.Information($"{Name}.SendS2F41_AMIDA_TesterDownloadRecipe() Timeout.");
                   
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.Header[CItems.recipeAck] = (byte[])replyMsg.Root.Item(2).Item(2).Item(2).Value;
                    args.Header[CItems.lotIDAck] = (byte[])replyMsg.Root.Item(2).Item(3).Item(2).Value;
                    args.Header[CItems.S2F41Ack] = "1";
                    args.SetReturnCodeNG("Send_S2F41:SendS2F41_AMIDA_TesterDownloadRecipe, Equipment Reject.");
                    CimLogger.Information($"{Name}.Send_S2F41:SendS2F41_AMIDA_TesterDownloadRecipe() Equipment Reject.");
                    return;
                }

                args.Header[CItems.S2F41Ack] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41:SendS2F41_AMIDA_TesterDownloadRecipe() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("SendS2F41_AMIDA_TesterDownloadRecipe:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41:SendS2F41_AMIDA_TesterDownloadRecipe() Execute Error.");
            }
        }


        /// <summary>
        /// UF200R流程 ，UF200R 可搭配Raytrex_E4980A
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_UF200R_ProberDownloadRecipe(XfwArgs args)
        {
            try
            {
                var ocrName = Dict.Current.OCRName;
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(ocrName, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_UF200RProberDownloadRecipe() The EAP has been switched Automatic Operation");
                    return;
                }

                var customerLotId = Dict.Current.lotInfo.customerLotId; //args.Header[CItems.CustomerLotId]?.ToString();
                var eqpID = Dict.Current.lotInfo.eqptID; //args.Header[CItems.EqpID].ToString();
                var productid = Dict.Current.lotInfo.productId;
                var recipeName = Dict.Current.lotInfo.proberRecipe;
                ; //args.Header[CItems.ProberRecipe]?.ToString();
                var lotID = Dict.Current.lotInfo.lotId; //args.Header[CItems.LotID]?.ToString();
                var lotLists = Dict.Current.lotInfo.LotLists; //选片
                var IsAlignment = Dict.Current.lotInfo.Alignment; // "N"
                var RecommendODValue = Dict.Current.RecommendOD;
                var rcflag = Dict.Current.lotInfo.rcflag; //runcard 标记：N/Y
                var probercard = Dict.Current.lotInfo.ProberCardId;
                var mesLists = Dict.Current.lotInfo.MesWaferList;
                var TestMode = Dict.Current.lotInfo.TestMode.Split("-")[0];
                var LoadModeValue = "";
                var unitidLists = Dict.Current.lotInfo.UnitidLists;
                CimLogger.Information("原始lotLists:" + lotLists);
                CimLogger.Information("MESmesLists:" + mesLists);
                CimLogger.Information("UnitidLists:" + unitidLists);
                if (!string.IsNullOrEmpty(lotLists))
                {
                    //Sequential;Sample;Assign
                    if (TestMode == WaferTestModeType.Sequential.ToString())
                    {
                        Dict.Current.lotInfo.LotLists = lotLists + "-" + "SEQUENTIAL";
                        lotLists = "";
                        LoadModeValue = "SEQUENTIAL"; //SEQUENTIAL
                    }
                    else if (TestMode == WaferTestModeType.Sample.ToString())
                    {
                        //抽测 sampleID
                        LoadModeValue = "SAMPLE";
                        Dict.Current.lotInfo.LotLists = lotLists + "-" + "SAMPLE";
                    }
                    else if (TestMode == WaferTestModeType.Assign.ToString())
                    {
                        //走第三个按钮ASSIGN
                        LoadModeValue = "ASSIGN";
                        lotLists = lotLists.Split(';')[0];
                        Dict.Current.lotInfo.LotLists = lotLists + "-" + "ASSIGN";
                    }
                }

                if (Dict.Current.lotInfo.facilityId != "F2")
                {
                    if (!string.IsNullOrEmpty(customerLotId)) //如果这个值不为空，则Prober识别该值
                    {
                        lotID = customerLotId;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(lotID))
                        {
                            var index = lotID.IndexOf('.');
                            if (index > 0)
                            {
                                lotID = lotID.Substring(0, index); //比如AA9370.01   Prober只识别AA9370
                            }
                        }
                    }
                }

                if (Dict.Current.IsEngineeringMode == "Y") //如果时工程片测试，则使用配置的Recipe和LotID
                {
                    lotID = Dict.Current.ProberLotID;
                    recipeName = Dict.Current.ProberRecipe;
                }

                if (string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning(
                        $"{Name}.Send_S2F41_UF200RProberDownloadRecipe() 发送给OCR的数据异常.lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.S2F41_UF200RProberDownloadRecipe(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var isCheckNeedleMark = "Y";
                var context = XfwContext.GetSECSContext(ocrName);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "UF200R_PROBERDOWNLOADRECIPE";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                //var IsChangePPIDList = new SECSItem(eSECS_FORMAT.LIST);
                //IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsChangePPID });
                //IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "Y" }); //Y ：更换  N：不更换//rpa 识别
                //secondlist.Add(IsChangePPIDList);

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //Recipe名称
                secondlist.Add(RecipeNameList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);

                var ProductIDList = new SECSItem(eSECS_FORMAT.LIST);
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProductID });
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = productid }); //产品ID 
                secondlist.Add(ProductIDList);

                var LoadModes = new SECSItem(eSECS_FORMAT.LIST);
                LoadModes.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LoadMode });
                LoadModes.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LoadModeValue }); //选片的模式
                secondlist.Add(LoadModes);

                var LotListsList = new SECSItem(eSECS_FORMAT.LIST);
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = SlotLists });
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotLists }); //  选片集合
                secondlist.Add(LotListsList);

                var WaferIdList = new SECSItem(eSECS_FORMAT.LIST);
                WaferIdList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = WaferIdCodeLists });
                WaferIdList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = unitidLists }); //  MES wafercode 集合
                secondlist.Add(WaferIdList);

                var IsCheckNeedleMarkList = new SECSItem(eSECS_FORMAT.LIST);
                IsCheckNeedleMarkList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsCheckNeedleMark });
                IsCheckNeedleMarkList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsAlignment }); //Y ：对针  N：不对针
                secondlist.Add(IsCheckNeedleMarkList);

                var RecommendODList = new SECSItem(eSECS_FORMAT.LIST);
                RecommendODList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = RecommendOD });
                RecommendODList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = RecommendODValue }); //OD推荐值
                secondlist.Add(RecommendODList);

                var ProberCardList = new SECSItem(eSECS_FORMAT.LIST);
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProberCardID });
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = probercard }); //针卡ID 
                secondlist.Add(ProberCardList);

                var Rcflagist = new SECSItem(eSECS_FORMAT.LIST);
                Rcflagist.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = RCFLAG });
                Rcflagist.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = rcflag }); //runcard 标记
                secondlist.Add(Rcflagist);

                requestMsg.Root.Add(secondlist);

                var messagess = TranslateMsg.GetTranslation("SendS2F41_UF200R_ProberDownloadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.Header[CItems.S2F41Ack] = "2";
                    args.SetReturnCodeNG("Send_S2F41:UF200RProberDownloadRecipe, Timeout");
                    CimLogger.Information($"{Name}.Send_S2F41_UF200RProberDownloadRecipe() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41-UF200RProberDownloadRecipe 失败，接口超时", eqpID,
                        //Dict.Current.lotInfo.lotId);
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.Header[CItems.recipeAck] = (byte[])replyMsg.Root.Item(2).Item(2).Item(2).Value;
                    args.Header[CItems.lotIDAck] = (byte[])replyMsg.Root.Item(2).Item(3).Item(2).Value;
                    args.Header[CItems.S2F41Ack] = "1";
                    args.SetReturnCodeNG("Send_S2F41:UF200RProberDownloadRecipe, Equipment Reject.");
                    CimLogger.Information($"{Name}.Send_S2F41:UF200RProberDownloadRecipe() Equipment Reject.");
                
                    return;
                }

                args.Header[CItems.S2F41Ack] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41:UF200RProberDownloadRecipe() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-UF200RProberDownloadRecipe 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_UF200RProberDownloadRecipe:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41:UF200RProberDownloadRecipe() Execute Error.");
            }
        }

        #region UF2000-DTS1000 命令

        /// <summary>
        /// DTS1000+UF2000
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_DTS1000_TesterDownloadRecipe(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "DTS1000_TESTERDOWNLOADRECIPE"; //DTS1000_TesterDownloadRecipe
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                var userName = Dict.Current.lotInfo.userName;
                var recipeName = Dict.Current.lotInfo.testerProgram;
                var lotID = Dict.Current.lotInfo.lotId;
                var productid = Dict.Current.lotInfo.productId;
                var probercard = Dict.Current.lotInfo.ProberCardId;

                if (string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning(
                        $"{Name}.Send_S2F41_DTS1000_TesterDownloadRecipe() 发送给OCR的数据异常，lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_DTS1000_TesterDownloadRecipe(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //RecipeName
                secondlist.Add(RecipeNameList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);

                var ProductIDList = new SECSItem(eSECS_FORMAT.LIST);
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProductID });
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = productid }); //产品ID 
                secondlist.Add(ProductIDList);

                var ProberCardList = new SECSItem(eSECS_FORMAT.LIST);
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProberCardID });
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = probercard }); //针卡ID 
                secondlist.Add(ProberCardList);

                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41_DTS1000_TesterDownloadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:DownLoadRecipeToTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_DownLoadRecipeToTester() Timeout.");

                    args.Header[CItems.S2F41AckToTester] = "2";
                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_DownLoadRecipeToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Error.");
            }
        }

        public void Send_S2F41_DTS1000_StartTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "DTS1000_STARTTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41StartTestToTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:DTS1000StartTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_DTS1000StartTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41_DTS1000StartTester 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTestToTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_DTS1000StartTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-DTS1000StartTester 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41-DTS1000StartTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-DTS1000StartTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }

        /// <summary>
        /// 清除数据
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_ClearData(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "ClearData";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:ClearData, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_ClearData() Timeout.");
                    //dbServer.InsertMsgInfo("发送Send_S2F41_ClearData 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send Send_S2F41_ClearData, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_ClearData() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                    //dbServer.InsertMsgInfo("发送Send_S2F41_ClearData 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_Send_S2F41_ClearData() Execute Success.");
                //dbServer.InsertMsgInfo("发送Send_S2F41_ClearData 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("Send_S2F41_ClearData:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_ClearData() Execute Error.");
            }
        }

        public void Send_S2F41_DTS1000_EndTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "DTS1000_ENDTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41EndTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41-EndTester 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                Dict.Current.lotInfo = new LotInfo();
                CimLogger.Information($"{Name}.Send_S2F41_EndTestToTester() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }


        public void Send_S2F41_UF2000_TrackOut(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "UF2000_TRACKOUT";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41EndProbe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:EndProbe, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndProbe() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41-EndProbe 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToProbe] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:EndProbe, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndProbe() Equipment Reject.");
                    args.Header[CItems.S2F41AckToProbe] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-EndProbe 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToProbe] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_EndProbe() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-EndProbe 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndProbe:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndProbe() Execute Error.");
            }
        }

        #endregion

        #region UF2000-ETS88 命令

        /// <summary>
        /// UF2000+ETS88
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_ETS88_TesterDownloadRecipe(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "ETS88_TESTERDOWNLOADRECIPE"; //ETS88_TesterDownloadRecipe
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                var userName = Dict.Current.lotInfo.userName;
                var recipeName = Dict.Current.lotInfo.testerProgram;
                var lotID = Dict.Current.lotInfo.lotId;
                var productid = Dict.Current.lotInfo.productId;
                var probercard = Dict.Current.lotInfo.ProberCardId;

                if (string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning(
                        $"{Name}.Send_S2F41_ETS88_TesterDownloadRecipe() 发送给OCR的数据异常，lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_ETS88_TesterDownloadRecipe(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //RecipeName
                secondlist.Add(RecipeNameList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);


                var ProductIDList = new SECSItem(eSECS_FORMAT.LIST);
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProductID });
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = productid }); //产品ID 
                secondlist.Add(ProductIDList);

                var ProberCardList = new SECSItem(eSECS_FORMAT.LIST);
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProberCardID });
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = probercard }); //针卡ID 
                secondlist.Add(ProberCardList);

                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41_ETS88_TesterDownloadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:DownLoadRecipeToTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_DownLoadRecipeToTester() Timeout.");

                    args.Header[CItems.S2F41AckToTester] = "2";
                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_DownLoadRecipeToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Error.");
            }
        }

        public void Send_S2F41_ETS88_StartTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var lotID = Dict.Current.lotInfo.lotId;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "ETS88_STARTTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);

                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41StartTestToTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:ETS88StartTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_ETS88StartTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41_ETS88StartTester 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTestToTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_ETS88StartTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-ETS800StartTester 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41-ETS88StartTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-ETS88StartTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }

        public void Send_S2F41_ETS88_EndTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "ETS88_ENDTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41EndTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41-EndTester 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-EndTester 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_EndTestToTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-EndTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }

        #endregion


        #region UF2000-DOT800 命令

        /// <summary>
        /// UF2000+DOT800
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_DOT800_TesterDownloadRecipe(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "DOT800_TESTERDOWNLOADRECIPE"; //ETS88_TesterDownloadRecipe
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                var userName = Dict.Current.lotInfo.userName;
                var recipeName = Dict.Current.lotInfo.testerProgram;
                var lotID = Dict.Current.lotInfo.lotId;
                var productid = Dict.Current.lotInfo.productId;
                var probercard = Dict.Current.lotInfo.ProberCardId;

                if (string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning(
                        $"{Name}.Send_S2F41_DOT800_TesterDownloadRecipe() 发送给OCR的数据异常，lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_DOT800_TesterDownloadRecipe(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //RecipeName
                secondlist.Add(RecipeNameList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);


                var ProductIDList = new SECSItem(eSECS_FORMAT.LIST);
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProductID });
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = productid }); //产品ID 
                secondlist.Add(ProductIDList);

                var ProberCardList = new SECSItem(eSECS_FORMAT.LIST);
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProberCardID });
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = probercard }); //针卡ID 
                secondlist.Add(ProberCardList);

                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41_DOT800_TesterDownloadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:DownLoadRecipeToTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_DownLoadRecipeToTester() Timeout.");

                    args.Header[CItems.S2F41AckToTester] = "2";
                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_DownLoadRecipeToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Error.");
            }
        }

        public void Send_S2F41_DOT800_StartTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "DOT800_STARTTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41StartTestToTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:DOT800StartTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_DOT800StartTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41_DOT800StartTester 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTestToTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_DOT800StartTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-DOT800StartTester 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41-DOT800StartTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-DOT800StartTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }

        public void Send_S2F41_DOT800_EndTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "DOT800_ENDTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41EndTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41-EndTester 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-EndTester 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_EndTestToTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-EndTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }

        #endregion

        #region UF200R-Rayterx_E4980A 命令

        /// <summary>
        /// UF200R+Rayterx_E4980A
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_Raytrex_E4980A_TesterDownloadRecipe(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "RAYTREX_E4980A_TESTERDOWNLOADRECIPE";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                var userName = Dict.Current.lotInfo.userName;
                var recipeName = Dict.Current.lotInfo.testerProgram;
                var lotID = Dict.Current.lotInfo.lotId;
                var productid = Dict.Current.lotInfo.productId;
                var probercard = Dict.Current.lotInfo.ProberCardId;
                var pcID = "0000";
                if (string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning(
                        $"{Name}.Send_S2F41_RAYTREX_E4980A_TesterDownloadRecipe() 发送给OCR的数据异常，lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_RAYTREX_E4980A_TesterDownloadRecipe(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //RecipeName
                secondlist.Add(RecipeNameList);

                var ProberCardList = new SECSItem(eSECS_FORMAT.LIST);
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProberCardID });
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = probercard }); //针卡ID 
                secondlist.Add(ProberCardList);

                var PCIDList = new SECSItem(eSECS_FORMAT.LIST);
                PCIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PcID });
                PCIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = pcID }); //针卡后的pcid,默认数字4个零 0000
                secondlist.Add(PCIDList);

                var OperatorIDList = new SECSItem(eSECS_FORMAT.LIST);
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = OperatorID });
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = userName }); //用户名ID 
                secondlist.Add(OperatorIDList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);

                var ProductIDList = new SECSItem(eSECS_FORMAT.LIST);
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProductID });
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = productid }); //产品ID 
                secondlist.Add(ProductIDList);


                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41_RAYTREX_E4980A_TesterDownloadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:DownLoadRecipeToTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_DownLoadRecipeToTester() Timeout.");

                    args.Header[CItems.S2F41AckToTester] = "2";
                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_DownLoadRecipeToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Error.");
            }
        }

        public void Send_S2F41_Raytrex_E4980A_StartTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "RAYTREX_E4980A_STARTTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41StartTestToTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:RAYTREX_E4980AStartTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_RAYTREX_E4980AStartTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41_RAYTREX_E4980AStartTester 失败，接口超时", eqpID,
                        //Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTestToTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_RAYTREX_E4980AStartTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                   

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41-RAYTREX_E4980AStartTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-RAYTREX_E4980AStartTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }

        public void Send_S2F41_Raytrex_E4980A_EndTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "RAYTREX_E4980A_ENDTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41EndTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41-EndTester 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-EndTester 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_EndTestToTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-EndTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }

        #endregion

        /// <summary>
        /// F2 UF200R+Rayterx_41000
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_Raytrex_41000_TesterDownloadRecipe(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "RAYTREX_41000_TESTERDOWNLOADRECIPE";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                var userName = Dict.Current.lotInfo.userName;
                var recipeName = Dict.Current.lotInfo.testerProgram;
                var lotID = Dict.Current.lotInfo.lotId;
                var productid = Dict.Current.lotInfo.productId;
                var probercard = Dict.Current.lotInfo.ProberCardId;
                var pcID = "0000";
                var pcbID = "1";
                if (string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning(
                        $"{Name}.Send_S2F41_RAYTREX_41000_TesterDownloadRecipe() 发送给OCR的数据异常，lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_RAYTREX_41000_TesterDownloadRecipe(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //RecipeName
                secondlist.Add(RecipeNameList);

                var PCBIDList = new SECSItem(eSECS_FORMAT.LIST);
                PCBIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PCBID });
                PCBIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = pcbID }); //PCBID 
                secondlist.Add(PCBIDList);

                var ProberCardList = new SECSItem(eSECS_FORMAT.LIST);
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProberCardID });
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = probercard }); //针卡ID 
                secondlist.Add(ProberCardList);

                var PCIDList = new SECSItem(eSECS_FORMAT.LIST);
                PCIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PcID });
                PCIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = pcID }); //针卡后的pcid,默认数字4个零 0000
                secondlist.Add(PCIDList);

                var OperatorIDList = new SECSItem(eSECS_FORMAT.LIST);
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = OperatorID });
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = userName }); //用户名ID 
                secondlist.Add(OperatorIDList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);

                var ProductIDList = new SECSItem(eSECS_FORMAT.LIST);
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProductID });
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = productid }); //产品ID 
                secondlist.Add(ProductIDList);


                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41_RAYTREX_41000_TesterDownloadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:DownLoadRecipeToTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_DownLoadRecipeToTester() Timeout.");

                    args.Header[CItems.S2F41AckToTester] = "2";
                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_DownLoadRecipeToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Error.");
            }
        }

        public void Send_S2F41_Raytrex_41000_StartTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "RAYTREX_41000_STARTTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41StartTestToTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:RAYTREX_41000StartTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_RAYTREX_41000StartTester() Timeout.");
                   

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTestToTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_RAYTREX_41000StartTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                   

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41-RAYTREX_41000StartTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-RAYTREX_41000StartTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }

        public void Send_S2F41_Raytrex_41000_EndTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "RAYTREX_41000_ENDTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41EndTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41-EndTester 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-EndTester 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_EndTestToTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-EndTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }

        #region UF2000-联动 命令

        public void Send_S2F41_LianDong_TesterDownloadRecipe(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "LIANDONG_TESTERDOWNLOADRECIPE"; //LianDong_TesterDownloadRecipe
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                var userName = Dict.Current.lotInfo.userName;
                var recipeName = Dict.Current.lotInfo.testerProgram;
                var lotID = Dict.Current.lotInfo.lotId;
                var productid = Dict.Current.lotInfo.productId;
                var probercard = Dict.Current.lotInfo.ProberCardId;
                var pcID = "0000";
                if (string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning(
                        $"{Name}.Send_S2F41_LianDong_TesterDownloadRecipe() 发送给OCR的数据异常，lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_LianDong_TesterDownloadRecipe(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //RecipeName
                secondlist.Add(RecipeNameList);

                var OperatorIDList = new SECSItem(eSECS_FORMAT.LIST);
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = OperatorID });
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = userName }); //用户名ID 
                secondlist.Add(OperatorIDList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);

                var ProberCardList = new SECSItem(eSECS_FORMAT.LIST);
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProberCardID });
                ProberCardList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = probercard }); //针卡ID 
                secondlist.Add(ProberCardList);

                var TestSceneList = new SECSItem(eSECS_FORMAT.LIST);
                TestSceneList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "TESTSCENE" });
                TestSceneList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "NoramlTest" }); //LotID
                secondlist.Add(TestSceneList);

                var OperationSceneList = new SECSItem(eSECS_FORMAT.LIST);
                OperationSceneList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "OPERATIONSCENE" });
                OperationSceneList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "PRODUCTION" }); //test mode
                secondlist.Add(OperationSceneList);

                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("Send_TesterDownloadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:DownLoadRecipeToTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_DownLoadRecipeToTester() Timeout.");

                    args.Header[CItems.S2F41AckToTester] = "2";
                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_DownLoadRecipeToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_DownLoadRecipeToTester() Execute Error.");
            }
        }

        public void Send_S2F41_LianDong_StartTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "LIANDONG_STARTTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41StartTestToTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:LianDongStartTester, Timeout");
                    CimLogger.Warning($"{Name}.LianDongStartTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送LianDongStartTester 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:StartTestToTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.LianDongStartTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-LianDongStartTester 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41-LianDongStartTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-LianDongStartTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_StartTestToTester() Execute Error.");
            }
        }

        public void Send_S2F41_LianDong_EndTester(XfwArgs args)
        {
            try
            {
                var eqpID = Dict.Current.OCRName;
                args.Header[CItems.EqpID] = eqpID;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "LIANDONG_ENDTESTER";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);
                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41EndTester");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Timeout");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Timeout.");
                    //dbServer.InsertMsgInfo("发送S2F41-EndTester 失败，接口超时", eqpID, Dict.Current.lotInfo.lotId);

                    args.Header[CItems.S2F41AckToTester] = "1";
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.SetReturnCodeNG("Send S2F41:EndTester, Equipment Reject.");
                    CimLogger.Warning($"{Name}.Send_S2F41_EndTester() Equipment Reject.");
                    args.Header[CItems.S2F41AckToTester] = "1";
                    //dbServer.InsertMsgInfo("发送S2F41-EndTester 失败，OCR执行失败", eqpID, Dict.Current.lotInfo.lotId);

                    return;
                }

                args.Header[CItems.S2F41AckToTester] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41_EndTestToTester() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-EndTester 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_EndTestToTester:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41_EndTestToTester() Execute Error.");
            }
        }

        #endregion

        /// <summary>
        /// SIDEA 矽电流程  可搭配amida
        /// </summary>
        /// <param name="args"></param>
        public void Send_S2F41_SIDEA_ProberDownloadRecipe(XfwArgs args)
        {
            try
            {
                var ocrName = Dict.Current.OCRName;
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(ocrName, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_SIDEA_ProberDownloadRecipe() The EAP has been switched Automatic Operation");
                    return;
                }

                var userName = Dict.Current.lotInfo.userName;
                var customerLotId = Dict.Current.lotInfo.customerLotId; //args.Header[CItems.CustomerLotId]?.ToString();
                var eqpID = Dict.Current.lotInfo.eqptID; //args.Header[CItems.EqpID].ToString();
                var productid = Dict.Current.lotInfo.productId;
                var recipeName = Dict.Current.lotInfo.proberRecipe;
                ; //args.Header[CItems.ProberRecipe]?.ToString();//     0056-16S-18711 "0001-16S-27288";//
                var lotID = Dict.Current.lotInfo
                    .lotId; //args.Header[CItems.LotID]?.ToString();//"DJJ632"; //  "DM0759"; //
                var lotLists = Dict.Current.lotInfo.LotLists; //选片
                var IsAlignment = Dict.Current.lotInfo.Alignment; // "N";//
                var mesLists = Dict.Current.lotInfo.MesWaferList;
                var TestMode = Dict.Current.lotInfo.TestMode.Split("-")[0];
                var LoadModeValue = "";
                var unitidLists = Dict.Current.lotInfo.UnitidLists;
                CimLogger.Information("原始lotLists:" + lotLists);
                CimLogger.Information("MESmesLists:" + mesLists);
                CimLogger.Information("UnitidLists:" + unitidLists);
                if (!string.IsNullOrEmpty(lotLists))
                {
                    //Sequential;Sample;Assign
                    if (TestMode == WaferTestModeType.Sequential.ToString())
                    {
                        Dict.Current.lotInfo.LotLists = lotLists + "-" + "SEQUENTIAL";
                        lotLists = "";
                        LoadModeValue = "SEQUENTIAL"; //SEQUENTIAL
                    }
                    else if (TestMode == WaferTestModeType.Sample.ToString())
                    {
                        //抽测 sampleID
                        LoadModeValue = "SAMPLE";
                        Dict.Current.lotInfo.LotLists = lotLists + "-" + "SAMPLE";
                    }
                    else if (TestMode == WaferTestModeType.Assign.ToString())
                    {
                        //走第三个按钮ASSIGN
                        LoadModeValue = "ASSIGN";
                        lotLists = lotLists.Split(';')[0];
                        Dict.Current.lotInfo.LotLists = lotLists + "-" + "ASSIGN";
                    }
                }
                //if (!string.IsNullOrEmpty(customerLotId)) //如果这个值不为空，则Prober识别该值
                //{
                //    lotID = customerLotId;
                //}
                //else
                //{
                //    if (!string.IsNullOrEmpty(lotID))
                //    {
                //        var index = lotID.IndexOf('.');
                //        if (index > 0)
                //        {
                //            lotID = lotID.Substring(0, index);//比如AA9370.01   Prober只识别AA9370
                //        }
                //    }

                //}
                //lotID = "DM0759";//测试用的，正式运行必须注释
                if (Dict.Current.IsEngineeringMode == "Y") //如果时工程片测试，则使用配置的Recipe和LotID
                {
                    lotID = Dict.Current.ProberLotID;
                    recipeName = Dict.Current.ProberRecipe;
                }

                if (string.IsNullOrEmpty(lotID) || string.IsNullOrEmpty(recipeName))
                {
                    CimLogger.Warning(
                        $"{Name}.Send_S2F41_SIDEA_ProberDownloadRecipe() 发送给OCR的数据异常.lotID{lotID}，recipeName：{recipeName}");
                    var messages = TranslateMsg.GetTranslation("S2F41DownLoadRecipeLotInfoIsNull");
                    if (!(messages == null || messages.Count == 0))
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Alarm, messages, MessageOrigin.OCR);
                    }

                    args.SetReturnCodeNG(
                        $"{Name}.Send_S2F41_SIDEA_ProberDownloadRecipe(),The Data Send To OCR is Abnormal. Please Contact the EAP Personnel");
                    return;
                }

                var isCheckNeedleMark = "Y";
                var context = XfwContext.GetSECSContext(ocrName);
                var trans = context.GetTransaction(2, 41);
                var requestMsg = trans.Primary;
                requestMsg.Root.Item(1).Value = "SIDEA_PROBERDOWNLOADRECIPE";
                var secondlist = new SECSItem(eSECS_FORMAT.LIST);

                //var IsChangePPIDList = new SECSItem(eSECS_FORMAT.LIST);
                //IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsChangePPID });
                //IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = "Y" }); //Y ：更换  N：不更换//rpa 识别
                //secondlist.Add(IsChangePPIDList);
                var OperatorIDList = new SECSItem(eSECS_FORMAT.LIST);
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = OperatorID });
                OperatorIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = userName }); //用户名ID 
                secondlist.Add(OperatorIDList);

                var RecipeNameList = new SECSItem(eSECS_FORMAT.LIST);
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = PPID });
                RecipeNameList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = recipeName }); //Recipe名称
                secondlist.Add(RecipeNameList);

                var LotIDList = new SECSItem(eSECS_FORMAT.LIST);
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LotID });
                LotIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotID }); //LotID
                secondlist.Add(LotIDList);

                var ProductIDList = new SECSItem(eSECS_FORMAT.LIST);
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = ProductID });
                ProductIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = productid }); //产品ID 
                secondlist.Add(ProductIDList);

                var LoadModes = new SECSItem(eSECS_FORMAT.LIST);
                LoadModes.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LoadMode });
                LoadModes.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = LoadModeValue }); //选片的模式
                secondlist.Add(LoadModes);

                var LotListsList = new SECSItem(eSECS_FORMAT.LIST);
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = SlotLists });
                LotListsList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = lotLists }); //  选片集合
                secondlist.Add(LotListsList);

                var WaferIdList = new SECSItem(eSECS_FORMAT.LIST);
                WaferIdList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = WaferIdCodeLists });
                WaferIdList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = unitidLists }); //  MES wafercode 集合
                secondlist.Add(WaferIdList);


                var IsCheckNeedleMarkList = new SECSItem(eSECS_FORMAT.LIST);
                IsCheckNeedleMarkList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsCheckNeedleMark });
                IsCheckNeedleMarkList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsAlignment }); //Y ：对针  N：不对针
                secondlist.Add(IsCheckNeedleMarkList);

                //var IsChangePPIDList = new SECSItem(eSECS_FORMAT.LIST);
                //IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsCheckNeedleMark }); //是否对针标志
                //IsChangePPIDList.Add(new SECSItem(eSECS_FORMAT.ASCII) { Value = IsAlignment }); //Y ：对针  N：不对针
                //secondlist.Add(IsChangePPIDList);

                requestMsg.Root.Add(secondlist);
                var messagess = TranslateMsg.GetTranslation("SendS2F41_SIDEA_ProberDownloadRecipe");
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(eqpID, MessageType.Info, messagess, MessageOrigin.OCR);
                }

                var reply = context.SendAsync(trans);
                var replyMsg = reply.Result;
                if (replyMsg == null)
                {
                    args.Header[CItems.S2F41Ack] = "2";
                    args.SetReturnCodeNG("Send_S2F41:SIDEAProberDownloadRecipe, Timeout");
                    CimLogger.Information($"{Name}.Send_S2F41:SIDEAProberDownloadRecipe() Timeout.");
                 
                    return;
                }

                byte[] retCode = (byte[])replyMsg.Root.Item(1).Value;
                if (retCode[0] != 0 && retCode[0] != 4)
                {
                    args.Header[CItems.recipeAck] = (byte[])replyMsg.Root.Item(2).Item(2).Item(2).Value;
                    args.Header[CItems.lotIDAck] = (byte[])replyMsg.Root.Item(2).Item(3).Item(2).Value;
                    args.Header[CItems.S2F41Ack] = "1";
                    args.SetReturnCodeNG("Send_S2F41:SIDEAProberDownloadRecipe, Equipment Reject.");
                    CimLogger.Information($"{Name}.Send_S2F41:SIDEAProberDownloadRecipe() Equipment Reject.");
                

                    return;
                }

                args.Header[CItems.S2F41Ack] = "0";
                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Send_S2F41:SIDEAProberDownloadRecipe() Execute Success.");
                //dbServer.InsertMsgInfo("发送S2F41-SIDEAProberDownloadRecipe 成功", eqpID, Dict.Current.lotInfo.lotId);
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41_UF200RProberDownloadRecipe:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S2F41:SIDEAProberDownloadRecipe() Execute Error.");
            }
        }

        #region 设备被动接收 Response

        /// <summary>
        /// 发送设备是否可以通讯
        /// </summary>
        /// <param name="args"></param>
        public void Receive_S1F1_AreYouThere(XfwArgs args)
        {
            try
            {
                try
                {
                    var context = args.SECSData.Context;
                    var trans = args.SECSData.Trans;
                    var msg = trans.Primary;
                    var reply = trans.Secondary;
                    if (reply == null)
                    {
                        return;
                    }

                    context.ReplyMessage(args.SECSData.Trans);
                    CimLogger.Information($"{Name}.Receive_S1F1_AreYouThere() Execute Success.");
                }
                catch (Exception ex)
                {
                    args.SetReturnCodeNG("S1F1:" + ex.Message);
                    CimLogger.Error(ex, $"{Name}.Receive_S1F1_AreYouThere() Execute Error.");
                    return;
                }
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S1F1:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Send_S1F1_AreYouThere() Execute Error.");
            }
        }

        /// <summary>
        /// 返回建立通信信息
        /// </summary>
        /// <param name="args"></param>
        public void Receive_S1F13_EstablishCommunicationsSend(XfwArgs args)
        {
            try
            {
                var eqpID = args.SECSData.Context.Name;
                var context = XfwContext.GetSECSContext(eqpID);
                var trans = args.SECSData.Trans;

                var reply = trans.Secondary;
                reply.Root.Item(1).Value = 0;
                reply.Root.Item(2).Add(new SECSItem(eSECS_FORMAT.ASCII) { Name = "MDLN", Value = "EAPServer" });
                reply.Root.Item(2).Add(new SECSItem(eSECS_FORMAT.ASCII) { Name = "SOFTREV", Value = "v1.0.0" });

                context.ReplyMessage(args.SECSData.Trans);
                Dict.Current.OCRConnStatus = conn;
                var eqpType = args.SECSData.Context.Configuration.EqpType;
                if (eqpType == OCRType.TELOCR.ToString() || eqpType == OCRType.RaytrexOCR.ToString() ||
                    eqpType == OCRType.KeysightOCR.ToString() || eqpType == OCRType.DTS1000OCR.ToString() ||
                    eqpType == OCRType.ETS88OCR.ToString() || eqpType == OCRType.DOT800OCR.ToString() ||
                    eqpType == OCRType.Raytrex_E4980AOCR.ToString() || eqpType == OCRType.LianDongOCR.ToString() ||
                    eqpType == OCRType.SIDEA_LIANDONGOCR.ToString())
                {
                    Dict.Current.OCRTesterConnStatus = conn;
                }

                args.SetReturnCodeOK();
                CimLogger.Information($"{Name}.Receive_S1F13_EstablishCommunicationsSend() Execute Success.");
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S1F13:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Receive_S1F13_EstablishCommunicationsSend() Execute Error.");
                return;
            }
        }

        public void Receive_S5F1_AlarmReportSend(XfwArgs args)
        {
            try
            {
                var ocrName = Dict.Current.OCRName;
                var eqpID = args.SECSData.Context.Name;
                var context = XfwContext.GetSECSContext(ocrName);
                var trans = args.SECSData.Trans;
                var msg = trans.Primary;
                var reply = trans.Secondary;
                //if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                //{
                //    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                //    ClientService.ShowMessage(ocrName, MessageType.Info, messages, MessageOrigin.OCR);
                //    args.SetReturnCodeNG($"{Name}.Receive_S5F1_AlarmReportSend() The EAP has been switched Automatic Operation");
                //    return;
                //}
                if (msg.Root == null) //|| msg.Root.ItemCount != 3
                {
                    //rtCode = SECSAcknowledge.HANDLER_MISSING_PARAMETERS;
                    //CimLogger.Error($"{context.Name} => {ServerName}, MessageName: {nameof(Receive_S5F1_AlarmReportSend)}, {nameof(rtCode)} = {SECSAcknowledge.S5F1_MISSING_PARAMETERS}({nameof(SECSAcknowledge.S5F1_MISSING_PARAMETERS)})");
                    //发送S9F7（数据格式异常）
                    var tran = context.GetTransaction(9, 7);
                    context.SendMessage(tran);
                    args.SetReturnCodeNG("Receive_S5F1_AlarmReportSend: value format is error.");
                    CimLogger.Warning($"{Name}.Receive_S5F1_AlarmReportSend() value format is error.");
                    return;
                }

                //在判断值是否为空
                if (msg.Root.Item(1).ItemCount ==
                    0) //|| msg.Root.Item(2).ItemCount == 0 || msg.Root.Item(3).ItemCount == 0
                {
                    //rtCode = SECSAcknowledge.NumericalNull;
                    //CimLogger.Error($"{context.Name} => {ServerName}, MessageName: {nameof(Receive_S5F1_AlarmReportSend)}, {nameof(rtCode)} = {SECSAcknowledge.NumericalNull}({nameof(SECSAcknowledge.NumericalNull)})");
                    args.SetReturnCodeNG("Receive_S5F1_AlarmReportSend: value is null.");
                    CimLogger.Warning($"{Name}.Receive_S5F1_AlarmReportSend() value is null.");
                }
                else
                {
                    context.ReplyMessage(args.SECSData.Trans);
                    byte[] alcd = (Byte[])msg.Root.Item(1)?.Value;
                    string alarmcode = msg.Root.Item(2).Value?.ToString();
                    string alarmmsg = msg.Root.Item(3).Value?.ToString();
                    // eqpID = msg.Root.Item(4).Value?.ToString();
                    //var aX2 = Convert.ToString(Convert.ToInt32(alcd[0]), 2);
                    args.Header[CItems.EqpID] = eqpID;
                    args.Header[CItems.Alcd] = alcd;
                    args.Header[CItems.AlarmID] = alarmcode;
                    args.Header[CItems.AlarmMessage] = alarmmsg;
                    Dictionary<string, string> messages = null;
                    string alcds = "";
                    if (alcd[0] == 1)
                    {
                        //args.Header[CItems.CurState] = "3";//保存报警状态 上报事件给RCM
                        messages = TranslateMsg.GetTranslation("ReceiveS5F1Alarm");
                        alcds = "设备上报报警";
                    }
                    else
                    {
                        if (Dict.Current.CurState != "3" && !string.IsNullOrEmpty(Dict.Current.CurState))
                        {
                            args.Header[CItems.CurState] = Dict.Current.CurState;
                            if (Dict.Current.OCRCurrentStatus[ocrName] != Dict.Current.CurState)
                            {
                                Dict.Current.OCRCurrentStatus[ocrName] = Dict.Current.CurState;
                            }
                            else
                            {
                                //TODO:workflow判断NG不发上报RCM信息
                                args.SetReturnCodeNG($"ClearS5F1Alarm设备{ocrName}:状态重复，不上报RCM");
                                return;
                            }
                        }

                        messages = TranslateMsg.GetTranslation("ClearS5F1Alarm");
                        alcds = "设备消除报警";
                    }

                    if (messages != null && messages.Count != 0)
                    {
                        ClientService.ShowMessage(eqpID, MessageType.Info, messages, MessageOrigin.OCR);
                    }

                    Console.WriteLine($"{eqpID}上报报警=>alcd:{alcd},alarmcode:{alarmcode},alarmmsg:{alarmmsg}");
                    args.SetReturnCodeOK();
                    CimLogger.Information(
                        $"{Name}.Receive_S5F1_AlarmReportSend() Execute Success.alcd:{alcd},alarmcode:{alarmcode},alarmmsg:{alarmmsg}");
                    //dbServer.InsertMsgInfo($"收到S5F1- {alcds}", eqpID, Dict.Current.lotInfo.lotId);
                }
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S5F1:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Receive_S5F1_AlarmReportSend() Execute Error.");
                return;
            }
        }

        /// <summary>
        ///  OCR事件集
        /// </summary>
        /// <param name="args"></param>
        public void Receive_S6F11_EventReport(XfwArgs args)
        {
            try
            {
                var ocrName = Dict.Current.OCRName;
                // var eqpID = args.SECSData.Context.Name;
                //var eqptype = args.Header[CItems.EqpType].ToString();
                var messageType = MessageType.Info;
                var context = XfwContext.GetSECSContext(ocrName);
                var trans = args.SECSData.Trans;
                //收到的消息信息
                var msg = trans.Primary;
                if (msg == null)
                {
                    args.SetReturnCodeNG("Receive_S6F11_EventReport: msg is null.");
                    return;
                }

                var reply = trans.Secondary;
                context.ReplyMessage(args.SECSData.Trans);
                string dataid = msg.Root.Item(1).Value.ToString();
                string ceid = msg.Root.Item(2).Value.ToString();
                CimLogger.Information(
                    $"{Name}.Receive_S6F11_EventReport() ceid:{ceid} ;Dict.Current.EAPRunMode:{Dict.Current.EAPRunMode}");
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation && ceid != "101")
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    //CimLogger.Information($"{Name}.Receive_S6F11_EventReport() ceid:{ceid},手动操作");
                    ClientService.ShowMessage(ocrName, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG(
                        $"{Name}.Receive_S6F11_EventReport() The EAP has been switched Automatic Operation");
                    return;
                }

                args.Header[CItems.EqpID] = ocrName;
                args.Header[CItems.EventID] = ceid;
                Dictionary<string, string> messagess = null;

                //EventDic = new Dictionary<string, actionByEvent>() { { nameof(S6F11_CEID_101), delegate (XfwArgs args, SECSMessage msg, string ocrName) { S6F11_CEID_101(args, msg, ocrName); } } };
                //EventDic["S6F11_CEID_" + ceid].Invoke(args, msg, ocrName);
                //args.SetReturnCodeOK();
                switch (ceid)
                {
                    case "101": //RPA识别设备状态事件
                        //var eqpID = msg.Root.Item(3).Item(1).Item(2).Item(1).Value;
                        var curState = msg.Root.Item(3).Item(1).Item(2).Item(2).Value?.ToString();
                        if (curState == "0")
                        {
                            args.Header[CItems.CurState] = "2";
                        }
                        else if (curState == "2")
                        {
                            args.Header[CItems.CurState] = "1";
                        }
                        else if (curState == "3")
                        {
                            args.Header[CItems.CurState] = "3";
                        }

                        Dict.Current.CurState = args.Header[CItems.CurState]?.ToString();
                        CimLogger.Information(
                            $"{context.Name}.Receive_S6F11_EventReport() ceid:{ceid},设备当前状态:{curState}");
                        if (Dict.Current.OCRCurrentStatus[ocrName] != Dict.Current.CurState)
                        {
                            Dict.Current.OCRCurrentStatus[ocrName] = Dict.Current.CurState;
                        }
                        else
                        {
                            //TODO:workflow判断NG不发上报RCM信息
                            args.SetReturnCodeNG($"S6F11_EventReport设备{ocrName}:状态重复，不上报RCM");
                            return;
                        }

                        break;
                    case "102": //Prober结束测试事件
                        //var eqpID = msg.Root.Item(3).Item(1).Item(2).Item(1)?.Value;
                        Dict.Current.ProberRunStatus = "0"; //测试结束
                        Dict.Current.CurState = "1";
                        Console.WriteLine($"{ocrName}  prober结束测试");
                        //messagess = TranslateMsg.GetTranslation("ReceiveS6F11Event", "Prober结束测试");
                        CimLogger.Information($"{context.Name}.Receive_S6F11_EventReport() ceid:{ceid},Prober结束测试");
                        //dbServer.InsertMsgInfo($"收到S6F11- prober结束测试", ocrName, Dict.Current.lotInfo.lotId);
                        var rptRunHisTemp =
                            dbServer.SeleteRunHsiTemp(Dict.Current.lotInfo.eqptID, Dict.Current.lotInfo.lotId);

                        if (Dict.Current.EAPName == "EAPTelKeysight" || Dict.Current.EAPName == "EAPTelKeysight2")
                        {
                            messagess = TranslateMsg.GetTranslation("EndTestOKToEAP");
                            if (rptRunHisTemp != null) //TEL 类型的设备，OCR上报102 测试结束
                            {
                                rptRunHisTemp.END_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                                rptRunHisTemp.TRACKOUT_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                                dbServer.UpdateRunHsiTempByID(rptRunHisTemp);
                            }
                        }
                        else
                        {
                            messagess = TranslateMsg.GetTranslation("ReceiveS6F11Event", "Prober结束测试");
                            if (rptRunHisTemp != null)
                            {
                                rptRunHisTemp.END_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                                dbServer.UpdateRunHsiTemp(rptRunHisTemp);
                            }
                        }

                        //暂时注释
                        //if (Dict.Current.lotInfo.facilityId != "F2")
                        //{
                        //    Dict.Current.lotInfo = new LotInfo();
                        //}
                        string waferId = "";
                        string passDieCount = "";
                        CimLogger.Information($"收到RPA发送的waferId：{waferId}，passDieCount：{passDieCount}");
                        args.Header[CItems.waferId] = waferId; //"a001-01-a;a001-02-b;a001-03-c";
                        args.Header[CItems.passDieCount] = passDieCount; //"100;200;500"; 
                        args.Header[CItems.LotID] = Dict.Current.lotInfo.lotId;
                        args.Header[CItems.EqpID] = Dict.Current.lotInfo.eqptID;
                        if (rptRunHisTemp != null)
                        {
                            args.Header[CItems.LotID] = rptRunHisTemp.LOT_ID;
                            args.Header[CItems.CreateTime] = rptRunHisTemp.TRACKIN_TIME;
                            args.Header[CItems.FacilityId] = rptRunHisTemp.FACILITY_ID;
                            args.Header[CItems.UserName] = rptRunHisTemp.OPERATOR_ID;
                         
                            CimLogger.Information(
                                $"获取缓存的lotid:{rptRunHisTemp.LOT_ID},trackin时间:{rptRunHisTemp.TRACKIN_TIME}");
                        }

                        // Dict.Current.lotInfo = new LotInfo();
                        break;
                    case "103": //暂时不用  检验针距结果事件
                        //var eqpIDs = msg.Root.Item(3).Item(1).Item(2).Item(1)?.Value;
                        var IsCheck = msg.Root.Item(3).Item(1).Item(2).Item(2)?.Value;
                        var Reason = msg.Root.Item(3).Item(1).Item(2).Item(3)?.Value;
                        args.Header[CItems.IsCheck] = IsCheck;
                        args.Header[CItems.Reason] = Reason;
                        CimLogger.Information($"{Name}.Receive_S6F11_EventReport() ceid:{ceid},检验针距");
                        break;
                    case "104": //暂时不用 检验针痕结果事件
                        //var eqpIDs = msg.Root.Item(3).Item(1).Item(2).Item(1)?.Value;
                        var IsCheck1 = msg.Root.Item(3).Item(1).Item(2).Item(2)?.Value;
                        var Reason1 = msg.Root.Item(3).Item(1).Item(2).Item(3)?.Value;
                        args.Header[CItems.IsCheck] = IsCheck1;
                        args.Header[CItems.Reason] = Reason1;
                        CimLogger.Information($"{Name}.Receive_S6F11_EventReport() ceid:{ceid},检验针痕");
                        break;
                    case "105": //测试 Recipe、LotID设置成功事件
                        args.Header[CItems.EqpID] = ocrName;
                        args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                        args.Header[CItems.MessageType] = MessageType.Info.ToString();
                        //messagess = TranslateMsg.GetTranslation(CItems.S2F41TrackInOK);
                        //args.Header[CItems.TerminalMessage] = messagess;
                        if (Dict.Current.EAPName == EAPName.EAPServer.ToString())
                        {
                            messagess = TranslateMsg.GetTranslation(CItems.S2F41TrackInOK);
                            CimLogger.Information($"{Name}.Receive_S6F11_EventReport(): ceid:{ceid}  Recipe、LotID设置成功");
                            //dbServer.InsertMsgInfo($"收到S6F11 Recipe、LotID设置成功", ocrName, Dict.Current.lotInfo.lotId);
                            //dbServer.InsertMsgInfo($"Prober Recipe 校验成功", ocrName, Dict.Current.lotInfo.lotId);
                        }
                        else
                        {
                            messagess = TranslateMsg.GetTranslation("SendS2F41DownLoadRecipeToTester");
                            CimLogger.Information(
                                $"{Name}.Receive_S6F11_EventReport(): ceid:{ceid} 测试机 Recipe、LotID设置成功");
                            //dbServer.InsertMsgInfo($"收到S6F11 Recipe、LotID设置成功", ocrName, Dict.Current.lotInfo.lotId);
                            //dbServer.InsertMsgInfo($"Tester Recipe、LotID 校验成功", ocrName, Dict.Current.lotInfo.lotId);
                        }

                        args.Header[CItems.TerminalMessage] = messagess;
                        break;
                    case "106": //Prober开始测试事件
                        args.Header[CItems.EqpID] = ocrName;
                        args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                        args.Header[CItems.MessageType] = MessageType.Info.ToString();
                        messagess = TranslateMsg.GetTranslation(CItems.S2F41StartTestOK);
                        args.Header[CItems.TerminalMessage] = messagess;
                        CimLogger.Information($"{Name}.Receive_S6F11_EventReport(): ceid:{ceid} 开始测试成功");
                        //dbServer.InsertMsgInfo($"Prober Recipe 校验成功", ocrName, Dict.Current.lotInfo.lotId);
                        //dbServer.InsertMsgInfo($"收到S6F11 开始测试成功", ocrName, Dict.Current.lotInfo.lotId);
                        var rptRunHisTemps =
                            dbServer.SeleteRunHsiTemp(Dict.Current.lotInfo.eqptID, Dict.Current.lotInfo.lotId);
                        if (rptRunHisTemps != null)
                        {
                            rptRunHisTemps.IS_EAP_RUN = "1";
                            rptRunHisTemps.SELECT_WAFER_LIST = Dict.Current.lotInfo.LotLists;
                            rptRunHisTemps.START_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                            dbServer.UpdateRunHsiTemp(rptRunHisTemps);
                        }

                        break;
                    case "107": //RPA代操过程中 异常事件
                        var eqpID = msg.Root.Item(3).Item(1).Item(2).Item(1)?.ToString();
                        var result = msg.Root.Item(3).Item(1).Item(2).Item(2)?.ToString();
                        var ClientMsg = result;
                        var ExcMsgInfo = dbServer.SelectExcMsgByCodeID(result);

                        if (ExcMsgInfo != null)
                        {
                            ClientMsg = ExcMsgInfo.CODE_MESSAGE;
                        }

                        Dict.Current.AlarmID = "1"; //收到异常，将消息设置成alarm 1
                        messagess = new Dictionary<string, string>();
                        messagess.Add("EN", ClientMsg);
                        messagess.Add("CN", ClientMsg);
                        messageType = MessageType.Alarm;
                        ClientService.ShowMessage(eqpID, MessageType.Error, messagess, MessageOrigin.OCR);
                        CimLogger.Information($"{Name}.Receive_S6F11_EventReport(): ceid:{ceid} 异常原因：{ClientMsg}");
                        //dbServer.InsertMsgInfo($"收到S6F11 异常原因：{ClientMsg}", ocrName, Dict.Current.lotInfo.lotId);
                        break;
                    case "108": //测试机开始测试事件
                        CimLogger.Information($"{Name}.Receive_S6F11_EventReport() ceid:{ceid},Tester开始测试成功");
                        //dbServer.InsertMsgInfo($"收到S6F11-Tester开始测试成功", ocrName, Dict.Current.lotInfo.lotId);
                        messagess = TranslateMsg.GetTranslation("S6F11TestSuccess");
                        messageType = MessageType.Info;
                        break;
                    case "109": //测试机结束成功事件
                        CimLogger.Information($"{Name}.Receive_S6F11_EventReport() ceid:{ceid},Tester结束测试成功");
                        //dbServer.InsertMsgInfo($"收到S6F11-Tester结束测试成功", ocrName, Dict.Current.lotInfo.lotId);
                        messagess = TranslateMsg.GetTranslation("S6F11EndTestSuccess");
                        messageType = MessageType.Info;
                        break;
                    case "110": //同步进行流程，收到110 立刻执行Tester
                        CimLogger.Information(
                            $"{Name}.Receive_S6F11_EventReport() ceid:{ceid},Tester开始执行downloadrecipe");
                   
                        messagess = TranslateMsg.GetTranslation("S6F11TesterDownloadRecipe");
                        messageType = MessageType.Info;
                        break;
                    case "111": //收到111 立刻执行Tester【矽电+amida 组合】
                        CimLogger.Information($"{Name}.Receive_S6F11_EventReport() ceid:{ceid},Tester开始执行开始测试");
                        //dbServer.InsertMsgInfo($"收到S6F11-Tester开始执行StartTester", ocrName, Dict.Current.lotInfo.lotId);
                        messagess = TranslateMsg.GetTranslation("SendStartTest");
                        messageType = MessageType.Info;
                        break;
                    case "112": //rpa、eqp waferid 对比异常上报事件
                        var lotid = msg.Root.Item(3).Item(1).Item(1)?.ToString();
                        var value = msg.Root.Item(3).Item(1).Item(2)?.ToString();
                        var reasonsValue = msg.Root.Item(3).Item(1).Item(3)?.ToString();
                        CimLogger.Information(
                            $"{Name}.Receive_S6F11_EventReport() ceid:{ceid}, waferid 对比异常上报原因：{lotid + "_" + reasonsValue + "_" + value}");
                        // string[] stringsvalue=reasonsValue.Split(",");
                        //  var msgname = $"第{value}片WaferID错误，MES WaferID:{stringsvalue[0]},实际Waferid: {stringsvalue[1]}";
                        // CimLogger.Information($"{Name}.Receive_S6F11_EventReport() ceid:{ceid}, waferid 对比异常上报原因：{lotid+"_"+reasonsValue + "_"+ value}");
                        CimLogger.Information(reasonsValue);
                        args.Header[CItems.Reasons] = reasonsValue;
                        messagess = TranslateMsg.GetTranslation("SendHoldLot", reasonsValue);
                        messageType = MessageType.Info;
                        break;
                    case "13": //设备剩余跑货时间 事件
                        eqpID = msg.Root.Item(3).Item(1).Item(1)?.ToString();
                        var remainingTime = msg.Root.Item(3).Item(1).Item(2)?.ToString();
                        CimLogger.Information(
                            $"{Name}.Receive_S6F11_EventReport() ceid:{ceid}, 设备剩余跑货时间：{remainingTime}");
                        args.Header[CItems.RemainingTime] = remainingTime;
                        //messagess = TranslateMsg.GetTranslation("SendS6F11RemainingTime", remainingTime);
                        messageType = MessageType.Info;
                        break;
                    case "114": //检查人员是否有截取针痕图片
                        args.Header[CItems.EqpID] = ocrName;
                        args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                        args.Header[CItems.MessageType] = MessageType.Info.ToString();
                        messagess = TranslateMsg.GetTranslation("STARCheckZH");
                        args.Header[CItems.TerminalMessage] = messagess;
                        CimLogger.Information($"{Name}.Receive_S6F11_EventReport(): ceid:{ceid} 检查人员是否有截取针痕图片");
                        break;
                    case "115": //上报新STDF文件
                        args.Header[CItems.EqpID] = ocrName;
                        args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                        args.Header[CItems.MessageType] = MessageType.Info.ToString();
                        var s = msg.Root.Item(3).Item(1).Item(2).Item(1)?.ToString();
                        STDF stdf = System.Text.Json.JsonSerializer.Deserialize<STDF>(s);
                        args.Header[CItems.STDF] = stdf;
                        TrackoutLogger.Information($"{Name}.Receive_S6F11_EventReport(): ceid:{ceid} 设备上报{s}");
                        break;

                    default:
                        CimLogger.Information($"{Name}.Receive_S6F11_EventReport() Execute Success. ceid:{ceid}");
                        break;
                }

                args.SetReturnCodeOK();
                if (messagess != null && messagess.Count != 0)
                {
                    ClientService.ShowMessage(ocrName, messageType, messagess, MessageOrigin.OCR);
                }

                return;
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S6F11_EventReport:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Receive_S6F11_EventReport() Execute Error.");
            }
        }

        #endregion

        /// <summary>
        /// 检查工程人员是否有检查针痕截图信息
        /// </summary>
        /// <param name="args"></param>
        public void Send_CheckZH_Old(XfwArgs args)
        {
            try
            {
                var eqpId = Dict.Current.lotInfo.eqptID; //args.Header[CItems.EqpID]?.ToString();
                var lotId = Dict.Current.lotInfo.lotId;
                int CheckZHTime = CItems.CheckZHTime * 60;
                string uploadpath = "";
                Dictionary<string, string> messagess = null;
                string ftppathconfig = CItems.CheckZHPath.Replace('，', ','); //中文，替换,
                var ftprule = ftppathconfig.Split(',');
                if (ftprule.Length != 3 || !ftprule[0].ToLower().Contains("ftp://"))
                {
                    string msg1 = "检查存放目录配置不正确，正确格式为ftp://xxx,账号,密码，请检查";
                    args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                    args.Header[CItems.MessageType] = MessageType.Error.ToString();
                    messagess = TranslateMsg.GetTranslation("FTPErr");
                    args.Header[CItems.TerminalMessage] = messagess;
                    args.Header[CItems.Reasons] = msg1;
                    CimLogger.Information(msg1);
                    args.SetReturnCodeNG(msg1);
                    return;
                }

                string ftppath = ftppathconfig.Split(',')[0];
                string account = ftppathconfig.Split(',')[1];
                string pwd = ftppathconfig.Split(',')[2];
                while (CheckZHTime >= 0)
                {
                    var ftpfiles = FTPHelper.GetFtpList(ftppath, "", "LIST", account, pwd);
                    var filenum = ftpfiles.Count();
                    CimLogger.Information($"CheckZHPath路径下文件个数为：{filenum}");

                    if (System.IO.Directory.Exists(CItems.CheckZHUPLOADPath))
                    {
                        string tempdir = Directory.GetCurrentDirectory() + "/tempfile";
                        if (Directory.Exists(tempdir))
                        {
                            //清空目录数据
                            var files = Directory.GetFiles(tempdir);
                            foreach (var file in files)
                            {
                                File.Delete(file);
                            }
                        }
                        else
                        {
                            //创建临时目录
                            Directory.CreateDirectory(tempdir);
                        }

                        //下载到临时文件中
                        FTPHelper.DownFolder(ftppath, "", tempdir, account, pwd, Dict.Current.lotInfo.creatTime);

                        var fileitems = Directory.GetFiles(tempdir);

                        if (fileitems.Count() > 0)
                        {
                            string[] type = CItems.CheckZHType.Split(',');
                            bool flag = false;
                            int i = 1;
                            foreach (var file in fileitems)
                            {
                                string filehz = file.Substring(file.LastIndexOf('.') + 1); //文件后缀
                                string filename = file.Substring(file.LastIndexOf('\\') + 1); //文件后缀
                                if (type.Contains(filehz.ToLower()))
                                {
                                    string sourchpath = file;
                                    uploadpath = CItems.CheckZHUPLOADPath + "\\" + lotId + "_" +
                                                 DateTime.Now.ToString("yyyyMMddHHmmss") + "." + filehz;
                                    if (File.Exists(uploadpath))
                                    {
                                        args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                                        args.Header[CItems.MessageType] = MessageType.Error.ToString();
                                        string msg1 = "当前Lot针痕图片已存在，请检查";
                                        messagess = TranslateMsg.GetTranslation("CheckZHExist");
                                        args.Header[CItems.TerminalMessage] = messagess;
                                        args.Header[CItems.Reasons] = msg1;
                                        CimLogger.Information(msg1);
                                        args.SetReturnCodeNG(msg1);
                                        return;
                                    }

                                    File.Copy(sourchpath, uploadpath);
                                    File.Delete(sourchpath); //删除临时文件
                                    FTPHelper.Delete(ftppath + "/" + filename, account, pwd); //删除原文件
                                    flag = true;
                                    lotId = lotId + "_" + i.ToString();
                                    i++;
                                }
                            }

                            if (flag)
                            {
                                args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                                args.Header[CItems.MessageType] = MessageType.Info.ToString();
                                messagess = TranslateMsg.GetTranslation("CheckZHSuccess");
                                args.Header[CItems.TerminalMessage] = messagess;
                                CimLogger.Information($"检测到存在针痕图片，上传成功，上传路径：{uploadpath}");
                                args.SetReturnCodeOK();
                                return;
                            }
                        }
                    }
                    else
                    {
                        args.Header[CItems.MessageType] = MessageType.Error.ToString();

                        messagess = TranslateMsg.GetTranslation("CheckZHConfigErr");
                        args.Header[CItems.TerminalMessage] = messagess;
                        args.SetReturnCodeNG("配置项CheckZHPath或CheckZHUPLOADPath路径不存在，请检查！");
                        CimLogger.Error("配置项CheckZHPath或CheckZHUPLOADPath路径不存在，请检查！");
                        args.Header[CItems.Reasons] = "未检测到针痕图片";
                        return;
                    }

                    CheckZHTime--;
                    Thread.Sleep(1000);
                }

                args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                args.Header[CItems.MessageType] = MessageType.Error.ToString();
                string msg = "未检测到针痕图片";
                messagess = TranslateMsg.GetTranslation("CheckZHFail");
                args.Header[CItems.TerminalMessage] = messagess;
                args.Header[CItems.Reasons] = msg;
                CimLogger.Information(msg);
                args.SetReturnCodeNG(msg);
            }
            catch (Exception ex)
            {
                args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                args.Header[CItems.MessageType] = MessageType.Error.ToString();
                string msg = "检测到针痕图片异常，异常原因：" + ex.Message;
                var messagess = TranslateMsg.GetTranslation("CheckZHErr");
                args.Header[CItems.TerminalMessage] = messagess;
                args.Header[CItems.Reasons] = msg;
                args.SetReturnCodeNG("S6F11_EventReport:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Receive_S6F11_EventReport() Execute Error.");
            }
        }

        public void Send_CheckZH(XfwArgs args)
        {
            try
            {
                var eqpId = Dict.Current.lotInfo.eqptID; //args.Header[CItems.EqpID]?.ToString();
                var lotId = Dict.Current.lotInfo.lotId;
                int CheckZHTime = CItems.CheckZHTime * 60;
                string uploadpath = "";
                Dictionary<string, string> messagess = null;
                string ftppathconfig = CItems.CheckZHPath.Replace('，', ','); //中文，替换,
                var ftprule = ftppathconfig.Split(',');
                if (ftprule.Length != 3 || !ftprule[0].ToLower().Contains("ftp://"))
                {
                    string msg1 = "检查CheckZHPath存放目录配置不正确，正确格式为ftp://xxx,账号,密码，请检查";
                    args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                    args.Header[CItems.MessageType] = MessageType.Error.ToString();
                    messagess = TranslateMsg.GetTranslation("FTPErr");
                    args.Header[CItems.TerminalMessage] = messagess;
                    args.Header[CItems.Reasons] = msg1;
                    CimLogger.Information(msg1);
                    args.SetReturnCodeNG(msg1);
                    return;
                }

                string zhftppathconfig = CItems.CheckZHUPLOADPath.Replace('，', ','); //中文，替换,
                var zhftprule = zhftppathconfig.Split(',');
                if (zhftprule.Length != 3 || !zhftprule[0].ToLower().Contains("ftp://"))
                {
                    string msg1 = "检查CheckZHUPLOADPath存放目录配置不正确，正确格式为ftp://xxx,账号,密码，请检查";
                    args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                    args.Header[CItems.MessageType] = MessageType.Error.ToString();
                    messagess = TranslateMsg.GetTranslation("ZHFTPErr");
                    args.Header[CItems.TerminalMessage] = messagess;
                    args.Header[CItems.Reasons] = msg1;
                    CimLogger.Information(msg1);
                    args.SetReturnCodeNG(msg1);
                    return;
                }

                string ftppath = ftppathconfig.Split(',')[0];
                string account = ftppathconfig.Split(',')[1];
                string pwd = ftppathconfig.Split(',')[2];

                string zhftppath = zhftppathconfig.Split(',')[0];
                string zhaccount = zhftppathconfig.Split(',')[1];
                string zhpwd = zhftppathconfig.Split(',')[2];

                while (CheckZHTime >= 0)
                {
                    var ftpfiles = FTPHelper.GetFtpList(ftppath, "", "LIST", account, pwd);
                    var filenum = ftpfiles.Count();
                    CimLogger.Information($"CheckZHPath路径下文件个数为：{filenum}");

                    //if (Directory.Exists(CItems.CheckZHUPLOADPath))
                    //{
                    string tempdir = Directory.GetCurrentDirectory() + "/tempfile";
                    if (Directory.Exists(tempdir))
                    {
                        //清空目录数据
                        var files = Directory.GetFiles(tempdir);
                        foreach (var file in files)
                        {
                            File.Delete(file);
                        }
                    }
                    else
                    {
                        //创建临时目录
                        Directory.CreateDirectory(tempdir);
                    }

                    //下载到临时文件中
                    FTPHelper.DownFolder(ftppath, "", tempdir, account, pwd, Dict.Current.lotInfo.creatTime);

                    var fileitems = Directory.GetFiles(tempdir);

                    if (fileitems.Count() > 0)
                    {
                        string[] type = CItems.CheckZHType.Split(',');
                        bool flag = false;
                        int i = 1;
                        foreach (var file in fileitems)
                        {
                            string filehz = file.Substring(file.LastIndexOf('.') + 1); //文件后缀
                            string filename = file.Substring(file.LastIndexOf('\\') + 1); //文件后缀
                            if (type.Contains(filehz.ToLower()))
                            {
                                string sourchpath = file;
                                uploadpath = zhftppath + "/" + lotId + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") +
                                             "." + filehz;
                                //if (File.Exists(uploadpath))
                                //{
                                //    args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                                //    args.Header[CItems.MessageType] = MessageType.Error.ToString();
                                //    string msg1 = "当前Lot针痕图片已存在，请检查";
                                //    messagess = TranslateMsg.GetTranslation("CheckZHExist");
                                //    args.Header[CItems.TerminalMessage] = messagess;
                                //    args.Header[CItems.Reasons] = msg1;
                                //    CimLogger.Information(msg1);
                                //    args.SetReturnCodeNG(msg1);
                                //    return;
                                //}
                                //File.Copy(sourchpath, uploadpath);
                                FTPHelper.UploadFile(uploadpath, sourchpath, zhaccount, zhpwd);
                                File.Delete(sourchpath); //删除临时文件
                                FTPHelper.Delete(ftppath + "/" + filename, account, pwd); //删除原文件
                                flag = true;
                                lotId = lotId + "_" + i.ToString();
                                i++;
                            }
                        }

                        if (flag)
                        {
                            args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                            args.Header[CItems.MessageType] = MessageType.Info.ToString();
                            messagess = TranslateMsg.GetTranslation("CheckZHSuccess");
                            args.Header[CItems.TerminalMessage] = messagess;
                            CimLogger.Information($"检测到存在针痕图片，上传成功，上传路径：{uploadpath}");
                            args.SetReturnCodeOK();
                            return;
                        }
                    }
                    //}
                    //else
                    //{
                    //    args.Header[CItems.MessageType] = MessageType.Error.ToString();

                    //    messagess = TranslateMsg.GetTranslation("CheckZHConfigErr");
                    //    args.Header[CItems.TerminalMessage] = messagess;
                    //    args.SetReturnCodeNG("配置项CheckZHPath或CheckZHUPLOADPath路径不存在，请检查！");
                    //    CimLogger.Error("配置项CheckZHPath或CheckZHUPLOADPath路径不存在，请检查！");
                    //    args.Header[CItems.Reasons] = "未检测到针痕图片";
                    //    return;
                    //}
                    CheckZHTime--;
                    Thread.Sleep(1000);
                }

                args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                args.Header[CItems.MessageType] = MessageType.Error.ToString();
                string msg = "未检测到针痕图片";
                messagess = TranslateMsg.GetTranslation("CheckZHFail");
                args.Header[CItems.TerminalMessage] = messagess;
                args.Header[CItems.Reasons] = msg;
                CimLogger.Information(msg);
                args.SetReturnCodeNG(msg);
            }
            catch (Exception ex)
            {
                args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                args.Header[CItems.MessageType] = MessageType.Error.ToString();
                string msg = "检测到针痕图片异常，异常原因：" + ex.Message;
                var messagess = TranslateMsg.GetTranslation("CheckZHErr");
                args.Header[CItems.TerminalMessage] = messagess;
                args.Header[CItems.Reasons] = msg;
                args.SetReturnCodeNG("S6F11_EventReport:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.Receive_S6F11_EventReport() Execute Error.");
            }
        }

        /// <summary>
        /// 针距检查结果
        /// </summary>
        /// <param name="args"></param>
        public void CheckNeedlePitch(XfwArgs args)
        {
            try
            {
                var eqpId = Dict.Current.lotInfo.eqptID; //args.Header[CItems.EqpID]?.ToString();
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(eqpId, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG($"{Name}.CheckNeedlePitch() The EAP has been switched Automatic Operation");
                    return;
                }

                args.Header[CItems.EqpID] = eqpId;
                var isCheck = args.Header[CItems.IsCheck]?.ToString(); //检查结果
                var reason = args.Header[CItems.Reason]?.ToString(); //问题原因
                args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();

                if (string.IsNullOrEmpty(isCheck))
                {
                    CimLogger.Warning($"{Name}. CheckNeedlePitch(): isCheck is null");
                    return;
                }

                if (!Dict.Current.NeedleResult.ContainsKey(CItems.CheckNeedlePitch))
                {
                    Dict.Current.NeedleResult.Add(CItems.CheckNeedlePitch, true);
                }

                if (isCheck.ToUpper() == "Y")
                {
                    //发送给Client端,针距检查OK
                    Dict.Current.NeedleResult[CItems.CheckNeedlePitch] = true;
                    args.Header[CItems.MessageType] = MessageType.Info.ToString();
                    Dictionary<string, string> msgs = TranslateMsg.GetTranslation(CItems.CheckNeedlePitchOK);
                    args.Header[CItems.TerminalMessage] = msgs;
                    CimLogger.Information($"{Name}.CheckNeedlePitch(): CheckNeedlePitch is Success");
                    args.SetReturnCodeOK();
                }
                else
                {
                    //发送给Client 端，针距检查有问题
                    Dict.Current.NeedleResult[CItems.CheckNeedlePitch] = false;
                    args.Header[CItems.MessageType] = MessageType.Error.ToString();
                    Dictionary<string, string> msgs = TranslateMsg.GetTranslation(CItems.CheckNeedlePitchNG, reason);
                    args.Header[CItems.TerminalMessage] = msgs;
                    CimLogger.Warning($"{Name}.CheckNeedlePitch(): CheckNeedlePitch is Fail");
                    args.SetReturnCodeNG("CheckNeedlePitch Fail:" + reason);
                }
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("CheckNeedlePitch:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.CheckNeedlePitch() Execute Error.");
                return;
            }
        }

        /// <summary>
        /// 针痕检查结果
        /// </summary>
        /// <param name="args"></param>
        public void CheckNeedleMark(XfwArgs args)
        {
            try
            {
                var eqpId = Dict.Current.OCRName; //Dict.Current.lotInfo.eqptID;//args.Header[CItems.EqpID]?.ToString();
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(eqpId, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG($"{Name}.CheckNeedleMark() The EAP has been switched Automatic Operation");
                    return;
                }

                args.Header[CItems.EqpID] = eqpId;
                var isCheck = args.Header[CItems.IsCheck]?.ToString(); //检查结果
                var reason = args.Header[CItems.Reason]?.ToString(); //问题原因
                args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                args.Header[CItems.EqpID] = eqpId;
                if (string.IsNullOrEmpty(isCheck))
                {
                    CimLogger.Warning($"{Name}.CheckNeedleMark(): isCheck is null");
                    return;
                }

                if (!Dict.Current.NeedleResult.ContainsKey(CItems.CheckNeedleMark))
                {
                    Dict.Current.NeedleResult.Add(CItems.CheckNeedleMark, true);
                }

                if (isCheck.ToUpper() == "Y")
                {
                    //发送给Client端,针痕检查OK
                    //args.SetReturnCodeOK("CheckNeedleMark success:");

                    Dict.Current.NeedleResult[CItems.CheckNeedleMark] = true;
                    args.Header[CItems.MessageType] = MessageType.Info.ToString();
                    Dictionary<string, string> msgs = TranslateMsg.GetTranslation(CItems.CheckNeedleMarkOK);
                    args.Header[CItems.TerminalMessage] = msgs;
                    CimLogger.Information($"{Name}.CheckNeedleMark(): CheckNeedleMark is Success");
                }
                else
                {
                    //发送给Client 端，针痕检查有问题
                    args.SetReturnCodeNG("CheckNeedleMark Fail:" + reason);
                    Dict.Current.NeedleResult[CItems.CheckNeedleMark] = false;
                    args.Header[CItems.MessageType] = MessageType.Error.ToString();
                    Dictionary<string, string> msgs = TranslateMsg.GetTranslation(CItems.CheckNeedleMarkNG, reason);
                    args.Header[CItems.TerminalMessage] = msgs;
                    CimLogger.Warning($"{Name}.CheckNeedlePitch(): CheckNeedleMark is Fail" + reason);
                }
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("CheckNeedleMark:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.CheckNeedleMark() Execute Error.");
                return;
            }
        }


        /// <summary>
        /// TrackIn结果
        /// </summary>
        /// <param name="args"></param>
        public void S2F41TrackInResult(XfwArgs args)
        {
            try
            {
                var s2f41Ack = args.Header[CItems.S2F41Ack]?.ToString();
                // var eqpId = args.Header[CItems.EqpID]?.ToString();
                var recipeAck = args.Header[CItems.recipeAck]?.ToBi();
                var lotIDAck = args.Header[CItems.lotIDAck]?.ToBi();
                var eqpId = Dict.Current.OCRName;
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(eqpId, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG($"{Name}.S2F41TrackInResult() The EAP has been switched Automatic Operation");
                    return;
                }

                args.Header[CItems.EqpID] = eqpId;
                args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                if (s2f41Ack == "0")
                {
                    //Prober设置Recipe、批次号，对针OK，发送消息给Client
                    args.Header[CItems.MessageType] = MessageType.Info.ToString();
                    Dictionary<string, string> msgs = TranslateMsg.GetTranslation(CItems.S2F41TrackInOK);
                    args.Header[CItems.TerminalMessage] = msgs;
                    CimLogger.Information($"{Name}.S2F41TrackInResult(): S2F41TrackIn OK");
                }
                else if (s2f41Ack == "1")
                {
                    args.Header[CItems.MessageType] = MessageType.Error.ToString();
                    if (recipeAck != null)
                    {
                        if (recipeAck[0] != 0)
                        {
                            //发送选择Recipe 失败消息给Client
                            Dictionary<string, string> msgs =
                                TranslateMsg.GetTranslation(CItems.S2F41TrackInNG, "设置Recipe");
                            args.Header[CItems.TerminalMessage] = msgs;
                            args.SetReturnCodeNG($"S2F41TrackInResult: recipeAck:{recipeAck[0]}");
                            CimLogger.Warning($"{Name}.S2F41TrackInResult(): 设置Recipe 失败");
                        }
                    }

                    if (lotIDAck != null)
                    {
                        if (lotIDAck[0] != 0)
                        {
                            //发送设置Lot 失败消息给Client
                            Dictionary<string, string> msgs =
                                TranslateMsg.GetTranslation(CItems.S2F41TrackInNG, "设置LotID");
                            args.Header[CItems.TerminalMessage] = msgs;
                            args.SetReturnCodeNG($"S2F41TrackInResult:lotIDAck:{lotIDAck[0]}");
                            CimLogger.Warning($"{Name}.S2F41TrackInResult(): 设置LotID 失败");
                        }
                    }
                }
                else if (s2f41Ack == "2" || string.IsNullOrEmpty(s2f41Ack))
                {
                    //发送设置Lot 失败消息给Client
                    Dictionary<string, string> msgs = TranslateMsg.GetTranslation(CItems.S2F41TrackInNG, "timeout");
                    args.Header[CItems.TerminalMessage] = msgs;
                    args.SetReturnCodeNG($"S2F41TrackInResult:lotIDAck:{lotIDAck[0]}");
                    CimLogger.Warning($"{Name}.S2F41TrackInResult(): timeout");
                }
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41TrackInResult:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.S2F41TrackInResult() Execute Error.");
                return;
            }
        }

        /// <summary>
        /// StartTest结果
        /// </summary>
        /// <param name="args"></param>
        public void S2F41StartTestResult(XfwArgs args)
        {
            try
            {
                var s2f41Ack = args.Header[CItems.S2F41Ack]?.ToString();
                //  var eqpId = args.Header[CItems.EqpID]?.ToString();
                var eqpId = Dict.Current.OCRName;
                if (Dict.Current.EAPRunMode == RunMode.ManualOperation)
                {
                    var messages = TranslateMsg.GetTranslation(CItems.ManualOperation);
                    ClientService.ShowMessage(eqpId, MessageType.Info, messages, MessageOrigin.OCR);
                    args.SetReturnCodeNG(
                        $"{Name}.S2F41StartTestResult() The EAP has been switched Automatic Operation");
                    return;
                }

                args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
                args.Header[CItems.EqpID] = eqpId;
                if (s2f41Ack == "0")
                {
                    //Prober开始测试成功，发送消息给Client
                    args.Header[CItems.MessageType] = MessageType.Info.ToString();
                    Dictionary<string, string> msgs = TranslateMsg.GetTranslation(CItems.S2F41StartTestOK);
                    args.Header[CItems.TerminalMessage] = msgs;
                    CimLogger.Information($"{Name}.S2F41StartTestResult(): 开始测试成功");
                }
                else
                {
                    //Prober开始测试失败，发送消息给Client
                    args.Header[CItems.MessageType] = MessageType.Error.ToString();
                    Dictionary<string, string> msgs =
                        TranslateMsg.GetTranslation(CItems.S2F41StartTestNG, " Interface timeout");
                    args.Header[CItems.TerminalMessage] = msgs;
                    CimLogger.Warning($"{Name}.S2F41StartTestResult(): 开始测试失败");
                }
            }
            catch (Exception ex)
            {
                args.SetReturnCodeNG("S2F41TrackInResult:" + ex.Message);
                CimLogger.Error(ex, $"{Name}.S2F41TrackInResult() Execute Error.");
                return;
            }
        }


        #region 暂时用不到

        private void EventDicAdd()
        {
            //EventDic = new Dictionary<string, actionByEvent>()
            //{
            //    { nameof(S6F11_CEID_101), delegate (XfwArgs args, SECSMessage msg, string ocrName) { S6F11_CEID_101(args, msg, ocrName); } } ,
            //    {nameof(S6F11_CEID_102), delegate (XfwArgs args, SECSMessage msg, string ocrName) { S6F11_CEID_102(args, msg, ocrName); } },
            //    {nameof(S6F11_CEID_103), delegate (XfwArgs args, SECSMessage msg, string ocrName) { S6F11_CEID_103(args, msg, ocrName); } },
            //    {nameof(S6F11_CEID_104), delegate (XfwArgs args, SECSMessage msg, string ocrName) { S6F11_CEID_104(args, msg, ocrName); } },
            //    {nameof(S6F11_CEID_105), delegate (XfwArgs args, SECSMessage msg, string ocrName) { S6F11_CEID_105(args, msg, ocrName); } },
            //    {nameof(S6F11_CEID_106), delegate (XfwArgs args, SECSMessage msg, string ocrName) { S6F11_CEID_106(args, msg, ocrName); } },
            //    {nameof(S6F11_CEID_107), delegate (XfwArgs args, SECSMessage msg, string ocrName) { S6F11_CEID_107(args, msg, ocrName); } },
            //};
        }

        private void S6F11_CEID_101(XfwArgs args, SECSMessage msg, string ocrName)
        {
            //var eqpID = msg.Root.Item(3).Item(1).Item(2).Item(1).Value;
            var curState = msg.Root.Item(3).Item(1).Item(2).Item(2).Value?.ToString();
            if (curState == "0")
            {
                args.Header[CItems.CurState] = "2";
            }
            else if (curState == "2")
            {
                args.Header[CItems.CurState] = "1";
            }

            Dict.Current.CurState = args.Header[CItems.CurState]?.ToString();
            CimLogger.Information($"{Name}.Receive_S6F11_EventReport() ceid:101,设备当前状态:{curState}");
        }

        private void S6F11_CEID_102(XfwArgs args, SECSMessage msg, string ocrName)
        {
            //var eqpID = msg.Root.Item(3).Item(1).Item(2).Item(1)?.Value;
            Dict.Current.ProberRunStatus = "0"; //测试结束
            Dict.Current.CurState = "1";
            Console.WriteLine($"{ocrName}  prober结束测试");
            var messagess = TranslateMsg.GetTranslation("ReceiveS6F11Event", "Prober结束测试");
            CimLogger.Information($"{Name}.Receive_S6F11_EventReport() ceid:102,Prober结束测试");
            if (messagess != null && messagess.Count != 0)
            {
                ClientService.ShowMessage(ocrName, MessageType.Info, messagess, MessageOrigin.OCR);
            }
        }

        private void S6F11_CEID_103(XfwArgs args, SECSMessage msg, string ocrName)
        {
            //var eqpIDs = msg.Root.Item(3).Item(1).Item(2).Item(1)?.Value;
            var IsCheck = msg.Root.Item(3).Item(1).Item(2).Item(2)?.Value;
            var Reason = msg.Root.Item(3).Item(1).Item(2).Item(3)?.Value;
            args.Header[CItems.IsCheck] = IsCheck;
            args.Header[CItems.Reason] = Reason;
            CimLogger.Information($"{Name}.Receive_S6F11_EventReport() ceid:103,检验针具");
        }

        private void S6F11_CEID_104(XfwArgs args, SECSMessage msg, string ocrName)
        {
            //var eqpIDs = msg.Root.Item(3).Item(1).Item(2).Item(1)?.Value;
            var IsCheck1 = msg.Root.Item(3).Item(1).Item(2).Item(2)?.Value;
            var Reason1 = msg.Root.Item(3).Item(1).Item(2).Item(3)?.Value;
            args.Header[CItems.IsCheck] = IsCheck1;
            args.Header[CItems.Reason] = Reason1;
            CimLogger.Information($"{Name}.Receive_S6F11_EventReport() ceid:104 ,检验针痕");
        }

        private void S6F11_CEID_105(XfwArgs args, SECSMessage msg, string ocrName)
        {
            args.Header[CItems.EqpID] = ocrName;
            args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
            args.Header[CItems.MessageType] = MessageType.Info.ToString();
            var messagess = TranslateMsg.GetTranslation(CItems.S2F41TrackInOK);
            args.Header[CItems.TerminalMessage] = messagess;
            CimLogger.Information($"{Name}.Receive_S6F11_EventReport(): ceid: 105 ,  Recipe、LotID设置成功");
            if (messagess != null && messagess.Count != 0)
            {
                ClientService.ShowMessage(ocrName, MessageType.Info, messagess, MessageOrigin.OCR);
            }
        }

        private void S6F11_CEID_106(XfwArgs args, SECSMessage msg, string ocrName)
        {
            args.Header[CItems.EqpID] = ocrName;
            args.Header[CItems.MessageOrigin] = MessageOrigin.OCR.ToString();
            args.Header[CItems.MessageType] = MessageType.Info.ToString();
            var messagess = TranslateMsg.GetTranslation(CItems.S2F41StartTestOK);
            args.Header[CItems.TerminalMessage] = messagess;
            CimLogger.Information($"{Name}.Receive_S6F11_EventReport(): ceid:106 开始测试成功");
        }

        private void S6F11_CEID_107(XfwArgs args, SECSMessage msg, string ocrName)
        {
            var eqpID = msg.Root.Item(3).Item(1).Item(2).Item(1)?.ToString();
            var result = msg.Root.Item(3).Item(1).Item(2).Item(2)?.ToString();
            var messagess = new Dictionary<string, string>();
            messagess.Add("EN", result);
            if (messagess != null && messagess.Count != 0)
            {
                ClientService.ShowMessage(ocrName, MessageType.Error, messagess, MessageOrigin.OCR);
            }

            CimLogger.Information($"{Name}.Receive_S6F11_EventReport(): ceid:107 异常事件：{result}");
        }

        #endregion
    }
}